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 {
|
for _, addSvc := range addServices {
|
||||||
haveSvc := false
|
haveSvc := false
|
||||||
for _, svc := range snap.Nodes[i].Node.Config.Services {
|
for _, svc := range snap.Nodes[i].Node.Config.Services {
|
||||||
|
|
||||||
if svc == addSvc {
|
if svc == addSvc {
|
||||||
haveSvc = true
|
haveSvc = true
|
||||||
break
|
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 {
|
if len(removeServices) > 0 {
|
||||||
var cleanedServices []string
|
var cleanedServices []string
|
||||||
haveSvc := false
|
|
||||||
for _, svc := range snap.Nodes[i].Node.Config.Services {
|
for _, svc := range snap.Nodes[i].Node.Config.Services {
|
||||||
|
haveSvc := false
|
||||||
for _, rmSvc := range removeServices {
|
for _, rmSvc := range removeServices {
|
||||||
if rmSvc == svc {
|
if rmSvc == svc {
|
||||||
haveSvc = true
|
haveSvc = true
|
||||||
|
|
|
||||||
|
|
@ -90,6 +90,7 @@ var (
|
||||||
snapshotFile = flag.String("snapshot", "", "create snapshot")
|
snapshotFile = flag.String("snapshot", "", "create snapshot")
|
||||||
loglevel = flag.Int("loglevel", 3, "verbosity of logs")
|
loglevel = flag.Int("loglevel", 3, "verbosity of logs")
|
||||||
rawlog = flag.Bool("rawlog", false, "remove terminal formatting from 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() {
|
func init() {
|
||||||
|
|
@ -306,7 +307,27 @@ func discoverySimulation(nodes, conns int, adapter adapters.NodeAdapter) (*simul
|
||||||
}
|
}
|
||||||
|
|
||||||
if *snapshotFile != "" {
|
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 {
|
if err != nil {
|
||||||
return nil, errors.New("no shapshot dude")
|
return nil, errors.New("no shapshot dude")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue