mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
p2p/simulation, swarm/network: Add selective services to discovery sim
This commit is contained in:
parent
b536ab172c
commit
776bdb0848
2 changed files with 34 additions and 10 deletions
|
|
@ -671,20 +671,23 @@ func (net *Network) snapshot(addServices []string, removeServices []string) (*Sn
|
|||
for _, addSvc := range addServices {
|
||||
haveSvc := false
|
||||
for _, svc := range snap.Nodes[i].Node.Config.Services {
|
||||
|
||||
if svc == addSvc {
|
||||
haveSvc = true
|
||||
break
|
||||
}
|
||||
if !haveSvc {
|
||||
snap.Nodes[i].Node.Config.Services = append(snap.Nodes[i].Node.Config.Services, addSvc)
|
||||
}
|
||||
|
||||
}
|
||||
if !haveSvc {
|
||||
log.Debug("addsvc in network", "addsvc", addSvc)
|
||||
snap.Nodes[i].Node.Config.Services = append(snap.Nodes[i].Node.Config.Services, addSvc)
|
||||
}
|
||||
}
|
||||
log.Debug("nodeservices", "svc", snap.Nodes[i].Node.Config.Services)
|
||||
if len(removeServices) > 0 {
|
||||
var cleanedServices []string
|
||||
haveSvc := false
|
||||
for _, svc := range snap.Nodes[i].Node.Config.Services {
|
||||
haveSvc := false
|
||||
for _, rmSvc := range removeServices {
|
||||
if rmSvc == svc {
|
||||
haveSvc = true
|
||||
|
|
|
|||
|
|
@ -85,11 +85,12 @@ func getDbStore(nodeID string) (*state.DBStore, error) {
|
|||
}
|
||||
|
||||
var (
|
||||
nodeCount = flag.Int("nodes", 10, "number of nodes to create (default 10)")
|
||||
initCount = flag.Int("conns", 1, "number of originally connected peers (default 1)")
|
||||
snapshotFile = flag.String("snapshot", "", "create snapshot")
|
||||
loglevel = flag.Int("loglevel", 3, "verbosity of logs")
|
||||
rawlog = flag.Bool("rawlog", false, "remove terminal formatting from logs")
|
||||
nodeCount = flag.Int("nodes", 10, "number of nodes to create (default 10)")
|
||||
initCount = flag.Int("conns", 1, "number of originally connected peers (default 1)")
|
||||
snapshotFile = flag.String("snapshot", "", "create snapshot")
|
||||
loglevel = flag.Int("loglevel", 3, "verbosity of logs")
|
||||
rawlog = flag.Bool("rawlog", false, "remove terminal formatting from logs")
|
||||
serviceOverride = flag.String("services", "", "remove or add services to the node snapshot; prefix with \"+\" to add, \"-\" to remove; example: +pss,-discovery")
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
|
@ -306,7 +307,27 @@ func discoverySimulation(nodes, conns int, adapter adapters.NodeAdapter) (*simul
|
|||
}
|
||||
|
||||
if *snapshotFile != "" {
|
||||
snap, err := net.Snapshot()
|
||||
var err error
|
||||
var snap *simulations.Snapshot
|
||||
if len(*serviceOverride) > 0 {
|
||||
log.Debug("fooooo")
|
||||
var addServices []string
|
||||
var removeServices []string
|
||||
for _, osvc := range strings.Split(*serviceOverride, ",") {
|
||||
log.Debug("serviceoverride", "osc", osvc)
|
||||
if strings.Index(osvc, "+") == 0 {
|
||||
log.Debug("add", "a", osvc)
|
||||
addServices = append(addServices, osvc[1:])
|
||||
} else if strings.Index(osvc, "-") == 0 {
|
||||
log.Debug("drop", "d", osvc)
|
||||
removeServices = append(removeServices, osvc[1:])
|
||||
}
|
||||
}
|
||||
snap, err = net.SnapshotWithServices(addServices, removeServices)
|
||||
} else {
|
||||
snap, err = net.Snapshot()
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.New("no shapshot dude")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue