Skip to content

Commit

Permalink
Merge pull request ethereum#75 from holisticode/refactor_events
Browse files Browse the repository at this point in the history
p2p/simulations: first attempt at event types
  • Loading branch information
zelig authored Apr 29, 2017
2 parents ac88a5a + 7752650 commit 8419f11
Show file tree
Hide file tree
Showing 4 changed files with 248 additions and 159 deletions.
24 changes: 4 additions & 20 deletions p2p/simulations/mocker.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,7 @@ func MockEvents(eventer *event.TypeMux, ids []*adapters.NodeId, conf *MockerConf
for i := 0; len(onNodes) > 0 && i < nodesDown; i++ {
c := rand.Intn(len(onNodes))
sn := onNodes[c]
err := eventer.Post(&NodeEvent{
Type: "node",
Action: "down",
node: sn,
})
err := eventer.Post(sn.EmitEvent(ControlEvent))
if err != nil {
panic(err.Error())
}
Expand All @@ -168,11 +164,7 @@ func MockEvents(eventer *event.TypeMux, ids []*adapters.NodeId, conf *MockerConf
for i := 0; len(offNodes) > 0 && i < nodesUp; i++ {
c := rand.Intn(len(offNodes))
sn := &Node{Id: offNodes[c]}
err := eventer.Post(&NodeEvent{
Type: "node",
Action: "up",
node: sn,
})
err := eventer.Post(sn.EmitEvent(ControlEvent))
if err != nil {
panic(err.Error())
}
Expand Down Expand Up @@ -231,11 +223,7 @@ func MockEvents(eventer *event.TypeMux, ids []*adapters.NodeId, conf *MockerConf
lab := ConnLabel(sc.One, sc.Other)
onConnsMap[lab] = len(onConns)
onConns = append(onConns, sc)
err := eventer.Post(&ConnEvent{
Type: "conn",
Action: "up",
conn: sc,
})
err := eventer.Post(sc.EmitEvent(ControlEvent))
if err != nil {
panic(err.Error())
}
Expand All @@ -247,11 +235,7 @@ func MockEvents(eventer *event.TypeMux, ids []*adapters.NodeId, conf *MockerConf
onConns = append(onConns[0:c], onConns[c+1:]...)
lab := ConnLabel(conn.One, conn.Other)
delete(onConnsMap, lab)
err := eventer.Post(&ConnEvent{
Type: "conn",
Action: "down",
conn: conn,
})
err := eventer.Post(conn.EmitEvent(ControlEvent))
if err != nil {
panic(err.Error())
}
Expand Down
Loading

0 comments on commit 8419f11

Please sign in to comment.