forked from protolambda/rumor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gossip.go
46 lines (39 loc) · 1.25 KB
/
gossip.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
package gossip
import (
"errors"
"github.com/cortze/rumor/control/actor/base"
"github.com/cortze/rumor/control/actor/gossip/topic"
"github.com/cortze/rumor/metrics"
"github.com/cortze/rumor/p2p/track"
"github.com/protolambda/ask"
)
type GossipCmd struct {
*base.Base
*metrics.GossipState
*metrics.GossipMetrics
Store track.ExtendedPeerstore
}
func (c *GossipCmd) Cmd(route string) (cmd interface{}, err error) {
switch route {
case "start":
cmd = &GossipStartCmd{Base: c.Base, GossipState: c.GossipState}
case "list":
cmd = &GossipListCmd{Base: c.Base, GossipState: c.GossipState}
case "message-db":
cmd = &GossipMessageDBCmd{Base: c.Base, GossipState: c.GossipState, GossipMetrics: c.GossipMetrics}
case "blacklist":
cmd = &GossipBlacklistCmd{Base: c.Base, GossipState: c.GossipState}
case "topic":
cmd = &topic.TopicCmd{Base: c.Base, GossipState: c.GossipState, GossipMetrics: c.GossipMetrics, Store: c.Store}
default:
return nil, ask.UnrecognizedErr
}
return cmd, nil
}
func (c *GossipCmd) Routes() []string {
return []string{"start", "list", "message-db", "blacklist", "topic"}
}
func (c *GossipCmd) Help() string {
return "Manage Libp2p GossipSub"
}
var NoGossipErr = errors.New("Must start gossip-sub first. Try 'gossip start'")