MCPcopy Create free account
hub / github.com/ethereum/node-crawler / startAPI

Function startAPI

cmd/crawler/api.go:35–95  ·  view source on GitHub ↗
(ctx *cli.Context)

Source from the content-addressed store, hash-verified

33)
34
35func startAPI(ctx *cli.Context) error {
36 var (
37 crawlerDBPath = ctx.String(crawlerDBFlag.Name)
38 apiDBPath = ctx.String(apiDBFlag.Name)
39 autovacuum = ctx.String(autovacuumFlag.Name)
40 busyTimeout = ctx.Uint64(busyTimeoutFlag.Name)
41 )
42
43 crawlerDB, err := openSQLiteDB(
44 crawlerDBPath,
45 autovacuum,
46 busyTimeout,
47 )
48 if err != nil {
49 return err
50 }
51
52 shouldInit := false
53 if _, err := os.Stat(apiDBPath); os.IsNotExist(err) {
54 shouldInit = true
55 }
56 nodeDB, err := openSQLiteDB(
57 apiDBPath,
58 autovacuum,
59 busyTimeout,
60 )
61 if err != nil {
62 return err
63 }
64 if shouldInit {
65 log.Info("DB did not exist, init")
66 if err := apidb.CreateDB(nodeDB); err != nil {
67 return err
68 }
69 }
70
71 // Start daemons
72 var wg sync.WaitGroup
73 wg.Add(3)
74
75 // Start reading daemon
76 go func() {
77 defer wg.Done()
78 newNodeDaemon(crawlerDB, nodeDB)
79 }()
80 // Start the drop daemon
81 go func() {
82 defer wg.Done()
83 dropDaemon(nodeDB, ctx.Duration(dropNodesTimeFlag.Name))
84 }()
85 // Start the API deamon
86 apiAddress := ctx.String(apiListenAddrFlag.Name)
87 apiDaemon := api.New(apiAddress, nodeDB)
88 go func() {
89 defer wg.Done()
90 apiDaemon.HandleRequests()
91 }()
92 wg.Wait()

Callers

nothing calls this directly

Calls 8

CreateDBFunction · 0.92
NewFunction · 0.92
openSQLiteDBFunction · 0.85
newNodeDaemonFunction · 0.85
dropDaemonFunction · 0.85
AddMethod · 0.80
HandleRequestsMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected