forked from protolambda/rumor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.go
50 lines (43 loc) · 1.25 KB
/
start.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
package gossip
import (
"context"
"errors"
"github.com/cortze/rumor/control/actor/base"
"github.com/cortze/rumor/metrics"
"github.com/cortze/rumor/p2p/gossip"
)
type GossipStartCmd struct {
*base.Base
*metrics.GossipState
*metrics.GossipMetrics
SeenFilter bool `ask:"--seen-filter" help:"Enable or Disable the Received Message Validation (Default: True)"`
}
func (c *GossipStartCmd) Help() string {
return "Start GossipSub"
}
func (c *GossipStartCmd) Default() {
c.SeenFilter = true
}
func (c *GossipStartCmd) Run(ctx context.Context, args ...string) error {
h, err := c.Host()
if err != nil {
return err
}
if c.GossipState.GsNode != nil {
return errors.New("Already started GossipSub")
}
c.GossipState.GsNode, err = gossip.NewGossipSub(c.ActorContext, h, c.SeenFilter)
if err != nil {
return err
}
c.Log.Info("Started GossipSub")
// Chech if the Validation Filter has been set
if c.SeenFilter {
c.Log.Info("Message Seen Filter has been Enabled, Messages WILL be dropped if we saw them before")
} else {
c.Log.Info("Message ValidSeenation Filter has been Disabled, Messages WONT be dropped when received")
}
// Doesn't really matter the flag, we have to add it the GossipState anyways
c.GossipState.SeenFilter = c.SeenFilter
return nil
}