forked from TheDistributedBay/TheDistributedBay
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
69 lines (57 loc) · 1.95 KB
/
main.go
File metadata and controls
69 lines (57 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"flag"
"log"
"runtime"
_ "expvar"
_ "net/http/pprof"
"github.com/TheDistributedBay/TheDistributedBay/database"
"github.com/TheDistributedBay/TheDistributedBay/frontend"
"github.com/TheDistributedBay/TheDistributedBay/importer"
"github.com/TheDistributedBay/TheDistributedBay/network"
"github.com/TheDistributedBay/TheDistributedBay/search"
"github.com/TheDistributedBay/TheDistributedBay/stats"
"github.com/TheDistributedBay/TheDistributedBay/tls"
"github.com/TheDistributedBay/TheDistributedBay/torrent"
)
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
log.SetFlags(log.Lshortfile | log.LstdFlags)
listen := flag.String("listen", ":7654", "Address to listen on")
connect := flag.String("connect", "", "Address to connect to")
httpAddress := flag.String("http", ":8080", "Address to listen on for HTTP")
dumpPath := flag.String("databasedump", "", "The path to a database dump that can be loaded. This should end in .csv.gz")
devAssets := flag.Bool("devassets", false, "Tells the front end to serve development assests instead of the precompiled production ones.")
flag.Parse()
db, err := database.NewTorrentDB("torrent.db")
if err != nil {
log.Fatal("Error opening torrent database", err)
}
cm := network.NewConnectionManager(db)
if *connect != "" {
c, err := tls.Dial(*connect)
if err != nil {
log.Fatalf("Error trying to connect to %v : %v", *connect, err)
}
cm.Handle(c)
} else {
l, err := tls.Listen(*listen)
if err != nil {
log.Fatalf("Error trying to listen to %v : %v", *listen, err)
}
go cm.Listen(l)
}
if *dumpPath != "" {
go importer.Import(*dumpPath, db)
}
go stats.ReportStats(db, cm)
go torrent.DiscoverPeers(cm, *listen)
s, err := search.NewSearcher(db, "thedistributedbay")
if err != nil {
log.Fatal("Error opening index", err)
}
statsUpdater := torrent.NewStatsUpdater(s, db)
log.Println("Running...")
frontend.Serve(httpAddress, db, s, *devAssets, statsUpdater)
cm.Close()
}