aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorFelix Hanley <felix@userspace.com.au>2017-06-09 08:40:39 +0000
committerFelix Hanley <felix@userspace.com.au>2017-06-09 08:40:39 +0000
commit1b97478a776e3ab2610d3b0358ae3d4fafaadd09 (patch)
tree37b3843f001b81f0be89b0efafb07949f8d267d7 /main.go
downloaddhtsearch-1b97478a776e3ab2610d3b0358ae3d4fafaadd09.tar.gz
dhtsearch-1b97478a776e3ab2610d3b0358ae3d4fafaadd09.tar.bz2
Where it's at.
As I have been running it. TODO: - web front-end and search - rate limiting - statistics - routing table logic - profiling (CPU mainly, mem seems ok)
Diffstat (limited to 'main.go')
-rwxr-xr-xmain.go79
1 files changed, 79 insertions, 0 deletions
diff --git a/main.go b/main.go
new file mode 100755
index 0000000..8450507
--- /dev/null
+++ b/main.go
@@ -0,0 +1,79 @@
+package main
+
+import (
+ "flag"
+ "fmt"
+ "os"
+)
+
+func main() {
+ var basePort, numNodes int
+ var debug bool = false
+ flag.IntVar(&basePort, "port", 6881, "listen port (and first of multiple ports)")
+ flag.IntVar(&numNodes, "nodes", 1, "number of nodes to start")
+ flag.BoolVar(&debug, "debug", false, "provide debug output")
+ flag.Parse()
+
+ // Slice of channels for DHT node output
+ torrents := make(chan Torrent)
+ peers := make(chan peer)
+
+ // Close upstreams channels
+ done := make(chan struct{})
+ defer close(done)
+
+ // Start DHTnodes
+ if debug {
+ fmt.Printf("Starting %d instance(s)\n", numNodes)
+ }
+
+ // Persistence
+ db, err := newDB()
+ if err != nil {
+ os.Exit(1)
+ }
+ defer db.Close()
+
+ // Create DHT nodes
+ for i := 0; i < numNodes; i++ {
+ // Consecutive port numbers
+ port := basePort + i
+ dht := newDHTNode("", port, peers)
+ dht.debug = debug
+ err = dht.run(done)
+ if err != nil {
+ os.Exit(1)
+ }
+ }
+
+ // Filter torrents
+ //processed := make(chan peer)
+
+ // Create BT nodes
+ for i := 0; i < numNodes; i++ {
+ btClient := newBTClient(peers, torrents)
+ btClient.debug = debug
+ err = btClient.run(done)
+ if err != nil {
+ os.Exit(1)
+ }
+ }
+
+ var t Torrent
+ for {
+ select {
+ case t = <-torrents:
+ length := t.Length
+ for _, f := range t.Files {
+ length = length + f.Length
+ }
+
+ fmt.Printf("Torrrent of size %d named: %s url: magnet:?xt=urn:btih:%s\n", length, t.Name, t.InfoHash)
+ // TODO add tags
+ err := db.updateTorrent(t)
+ if err != nil {
+ fmt.Printf("Error saving torrent: %q\n", err)
+ }
+ }
+ }
+}