-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.go
57 lines (44 loc) · 1.04 KB
/
main.go
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
package main
import (
"context"
"flag"
"log"
"time"
ds "github.com/ipfs/go-datastore"
ds_sync "github.com/ipfs/go-datastore/sync"
libp2p "github.com/libp2p/go-libp2p"
dht "github.com/libp2p/go-libp2p-kad-dht"
)
func main() {
logDial := flag.Bool("log-dial", false, "Log dial events in ipfs-crawl-events.json")
flag.Parse()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
if *logDial {
_, err := NewEventsLogger("ipfs-crawl-events.json")
if err != nil {
log.Fatal(err)
}
}
out, err := NewCrawlLog("ipfs-crawl.out")
if err != nil {
log.Fatal(err)
}
h, err := libp2p.New(ctx)
if err != nil {
log.Fatal(err)
}
log.Printf("I am %s\n", h.ID().Pretty())
dstore := ds_sync.MutexWrap(ds.NewMapDatastore())
dht := dht.NewDHTClient(ctx, h, dstore)
c := NewCrawler(ctx, h, dht, out)
err = c.Bootstrap()
if err != nil {
log.Fatal(err)
}
// wait a bit for the bootstrap
log.Printf("Waiting a minute for DHT bootstrap...")
time.Sleep(1 * time.Minute)
log.Printf("GO crawler GO!")
c.Crawl()
}