diff --git a/p2p/simulations/network.go b/p2p/simulations/network.go index 1cc481c244..e1254bb97b 100644 --- a/p2p/simulations/network.go +++ b/p2p/simulations/network.go @@ -66,7 +66,7 @@ type NetworkController struct { } // ServeStream subscribes to network events and sends them to the client as a -// stream of Server-Sent-Events, with each event being a JSON encoded CyUpdate +// stream of Server-Sent-Events, with each event being a JSON encoded SimUpdate // object func (n *NetworkController) ServeStream(w http.ResponseWriter, req *http.Request) { sub := n.events.Subscribe(ConnectivityEvents...) @@ -96,8 +96,8 @@ func (n *NetworkController) ServeStream(w http.ResponseWriter, req *http.Request for { select { case event := <-ch: - // convert the event to a CyUpdate - update, err := NewCyUpdate(event) + // convert the event to a SimUpdate + update, err := NewSimUpdate(event) if err != nil { write("error", err.Error()) return @@ -107,7 +107,7 @@ func (n *NetworkController) ServeStream(w http.ResponseWriter, req *http.Request write("error", err.Error()) return } - write("cyupdate", string(data)) + write("simupdate", string(data)) case <-clientGone: return } @@ -138,17 +138,17 @@ func NewNetworkController(net NetworkControl, nodesController *ResourceControlle Retrieve: &ResourceHandler{ Handle: func(msg interface{}, parent *ResourceController) (interface{}, error) { log.Trace(fmt.Sprintf("msg: %v", msg)) - cyConfig, ok := msg.(*CyConfig) + simConfig, ok := msg.(*SimConfig) if ok { - return UpdateCy(cyConfig, journal) + return UpdateSim(simConfig, journal) } snapshotConfig, ok := msg.(*SnapshotConfig) if ok { return Snapshot(snapshotConfig, journal) } - return nil, fmt.Errorf("invalid json body: must be CyConfig or SnapshotConfig") + return nil, fmt.Errorf("invalid json body: must be SimConfig or SnapshotConfig") }, - Type: reflect.TypeOf(&CyConfig{}), + Type: reflect.TypeOf(&SimConfig{}), }, // DELETE // Destroy: &ResourceHandler{ @@ -441,7 +441,7 @@ type NodeConfig struct { // TODO: ignored for now type QueryConfig struct { - Format string // "cy.update", "journal", + Format string // "sim.update", "journal", } type Know struct { diff --git a/p2p/simulations/session_controller_test.go b/p2p/simulations/session_controller_test.go index 92312fe401..c7e3d120f7 100644 --- a/p2p/simulations/session_controller_test.go +++ b/p2p/simulations/session_controller_test.go @@ -153,7 +153,7 @@ func TestUpdate(t *testing.T) { "remove": [], "message": [] }` - s, _ := json.Marshal(&CyConfig{}) + s, _ := json.Marshal(&SimConfig{}) resp := testResponse(t, "GET", url(port, "0"), bytes.NewReader(s)) if string(resp) != exp { t.Fatalf("incorrect response body. got\n'%v', expected\n'%v'", string(resp), exp) diff --git a/p2p/simulations/cytoscape.go b/p2p/simulations/sim_events.go similarity index 72% rename from p2p/simulations/cytoscape.go rename to p2p/simulations/sim_events.go index 37f3fe7956..1a472ddff4 100644 --- a/p2p/simulations/cytoscape.go +++ b/p2p/simulations/sim_events.go @@ -6,19 +6,19 @@ import ( "github.com/ethereum/go-ethereum/event" ) -// TODO: to implement cytoscape global behav -type CyConfig struct { +// TODO: to implement simulation global behav +type SimConfig struct { } -type CyData struct { +type SimData struct { Id string `json:"id"` Source string `json:"source,omitempty"` Target string `json:"target,omitempty"` Up bool `json:"up"` } -type CyElement struct { - Data *CyData `json:"data"` +type SimElement struct { + Data *SimData `json:"data"` Classes string `json:"classes,omitempty"` Group string `json:"group"` // selected: false, // whether the element is selected (default false) @@ -27,19 +27,19 @@ type CyElement struct { // grabbable: true, // whether the node can be grabbed and moved by the user } -type CyUpdate struct { - Add []*CyElement `json:"add"` - Remove []*CyElement `json:"remove"` - Message []*CyElement `json:"message"` +type SimUpdate struct { + Add []*SimElement `json:"add"` + Remove []*SimElement `json:"remove"` + Message []*SimElement `json:"message"` } -func NewCyUpdate(e *event.TypeMuxEvent) (*CyUpdate, error) { - var update CyUpdate - var el *CyElement +func NewSimUpdate(e *event.TypeMuxEvent) (*SimUpdate, error) { + var update SimUpdate + var el *SimElement entry := e.Data var action string if ev, ok := entry.(*NodeEvent); ok { - el = &CyElement{Group: "nodes", Data: &CyData{Id: ev.node.Id.String()}} + el = &SimElement{Group: "nodes", Data: &SimData{Id: ev.node.Id.String()}} action = ev.Action } else if ev, ok := entry.(*MsgEvent); ok { msg := ev.msg @@ -47,7 +47,7 @@ func NewCyUpdate(e *event.TypeMuxEvent) (*CyUpdate, error) { var source, target string source = msg.One.String() target = msg.Other.String() - el = &CyElement{Group: "msgs", Data: &CyData{Id: id, Source: source, Target: target}} + el = &SimElement{Group: "msgs", Data: &SimData{Id: id, Source: source, Target: target}} action = ev.Action } else if ev, ok := entry.(*ConnEvent); ok { // mutually exclusive directed edge (caller -> callee) @@ -61,7 +61,7 @@ func NewCyUpdate(e *event.TypeMuxEvent) (*CyUpdate, error) { source = conn.One.String() target = conn.Other.String() } - el = &CyElement{Group: "edges", Data: &CyData{Id: id, Source: source, Target: target}} + el = &SimElement{Group: "edges", Data: &SimData{Id: id, Source: source, Target: target}} action = ev.Action } else { return nil, fmt.Errorf("unknown event type: %T", entry) @@ -84,10 +84,10 @@ func NewCyUpdate(e *event.TypeMuxEvent) (*CyUpdate, error) { return &update, nil } -func UpdateCy(conf *CyConfig, j *Journal) (*CyUpdate, error) { - var update CyUpdate +func UpdateSim(conf *SimConfig, j *Journal) (*SimUpdate, error) { + var update SimUpdate j.Read(func(e *event.TypeMuxEvent) bool { - u, err := NewCyUpdate(e) + u, err := NewSimUpdate(e) if err != nil { panic(err.Error()) }