mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
p2p/simulations: renamed all occurrence of cytoscape
This commit is contained in:
parent
f02b408dd2
commit
aa91242dee
3 changed files with 28 additions and 28 deletions
|
|
@ -66,7 +66,7 @@ type NetworkController struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServeStream subscribes to network events and sends them to the client as a
|
// 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
|
// object
|
||||||
func (n *NetworkController) ServeStream(w http.ResponseWriter, req *http.Request) {
|
func (n *NetworkController) ServeStream(w http.ResponseWriter, req *http.Request) {
|
||||||
sub := n.events.Subscribe(ConnectivityEvents...)
|
sub := n.events.Subscribe(ConnectivityEvents...)
|
||||||
|
|
@ -96,8 +96,8 @@ func (n *NetworkController) ServeStream(w http.ResponseWriter, req *http.Request
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case event := <-ch:
|
case event := <-ch:
|
||||||
// convert the event to a CyUpdate
|
// convert the event to a SimUpdate
|
||||||
update, err := NewCyUpdate(event)
|
update, err := NewSimUpdate(event)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
write("error", err.Error())
|
write("error", err.Error())
|
||||||
return
|
return
|
||||||
|
|
@ -107,7 +107,7 @@ func (n *NetworkController) ServeStream(w http.ResponseWriter, req *http.Request
|
||||||
write("error", err.Error())
|
write("error", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
write("cyupdate", string(data))
|
write("simupdate", string(data))
|
||||||
case <-clientGone:
|
case <-clientGone:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -138,17 +138,17 @@ func NewNetworkController(net NetworkControl, nodesController *ResourceControlle
|
||||||
Retrieve: &ResourceHandler{
|
Retrieve: &ResourceHandler{
|
||||||
Handle: func(msg interface{}, parent *ResourceController) (interface{}, error) {
|
Handle: func(msg interface{}, parent *ResourceController) (interface{}, error) {
|
||||||
log.Trace(fmt.Sprintf("msg: %v", msg))
|
log.Trace(fmt.Sprintf("msg: %v", msg))
|
||||||
cyConfig, ok := msg.(*CyConfig)
|
simConfig, ok := msg.(*SimConfig)
|
||||||
if ok {
|
if ok {
|
||||||
return UpdateCy(cyConfig, journal)
|
return UpdateSim(simConfig, journal)
|
||||||
}
|
}
|
||||||
snapshotConfig, ok := msg.(*SnapshotConfig)
|
snapshotConfig, ok := msg.(*SnapshotConfig)
|
||||||
if ok {
|
if ok {
|
||||||
return Snapshot(snapshotConfig, journal)
|
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 /<networkId>/
|
// DELETE /<networkId>/
|
||||||
Destroy: &ResourceHandler{
|
Destroy: &ResourceHandler{
|
||||||
|
|
@ -441,7 +441,7 @@ type NodeConfig struct {
|
||||||
|
|
||||||
// TODO: ignored for now
|
// TODO: ignored for now
|
||||||
type QueryConfig struct {
|
type QueryConfig struct {
|
||||||
Format string // "cy.update", "journal",
|
Format string // "sim.update", "journal",
|
||||||
}
|
}
|
||||||
|
|
||||||
type Know struct {
|
type Know struct {
|
||||||
|
|
|
||||||
|
|
@ -153,7 +153,7 @@ func TestUpdate(t *testing.T) {
|
||||||
"remove": [],
|
"remove": [],
|
||||||
"message": []
|
"message": []
|
||||||
}`
|
}`
|
||||||
s, _ := json.Marshal(&CyConfig{})
|
s, _ := json.Marshal(&SimConfig{})
|
||||||
resp := testResponse(t, "GET", url(port, "0"), bytes.NewReader(s))
|
resp := testResponse(t, "GET", url(port, "0"), bytes.NewReader(s))
|
||||||
if string(resp) != exp {
|
if string(resp) != exp {
|
||||||
t.Fatalf("incorrect response body. got\n'%v', expected\n'%v'", string(resp), exp)
|
t.Fatalf("incorrect response body. got\n'%v', expected\n'%v'", string(resp), exp)
|
||||||
|
|
|
||||||
|
|
@ -6,19 +6,19 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: to implement cytoscape global behav
|
// TODO: to implement simulation global behav
|
||||||
type CyConfig struct {
|
type SimConfig struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type CyData struct {
|
type SimData struct {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
Source string `json:"source,omitempty"`
|
Source string `json:"source,omitempty"`
|
||||||
Target string `json:"target,omitempty"`
|
Target string `json:"target,omitempty"`
|
||||||
Up bool `json:"up"`
|
Up bool `json:"up"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CyElement struct {
|
type SimElement struct {
|
||||||
Data *CyData `json:"data"`
|
Data *SimData `json:"data"`
|
||||||
Classes string `json:"classes,omitempty"`
|
Classes string `json:"classes,omitempty"`
|
||||||
Group string `json:"group"`
|
Group string `json:"group"`
|
||||||
// selected: false, // whether the element is selected (default false)
|
// 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
|
// grabbable: true, // whether the node can be grabbed and moved by the user
|
||||||
}
|
}
|
||||||
|
|
||||||
type CyUpdate struct {
|
type SimUpdate struct {
|
||||||
Add []*CyElement `json:"add"`
|
Add []*SimElement `json:"add"`
|
||||||
Remove []*CyElement `json:"remove"`
|
Remove []*SimElement `json:"remove"`
|
||||||
Message []*CyElement `json:"message"`
|
Message []*SimElement `json:"message"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCyUpdate(e *event.TypeMuxEvent) (*CyUpdate, error) {
|
func NewSimUpdate(e *event.TypeMuxEvent) (*SimUpdate, error) {
|
||||||
var update CyUpdate
|
var update SimUpdate
|
||||||
var el *CyElement
|
var el *SimElement
|
||||||
entry := e.Data
|
entry := e.Data
|
||||||
var action string
|
var action string
|
||||||
if ev, ok := entry.(*NodeEvent); ok {
|
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
|
action = ev.Action
|
||||||
} else if ev, ok := entry.(*MsgEvent); ok {
|
} else if ev, ok := entry.(*MsgEvent); ok {
|
||||||
msg := ev.msg
|
msg := ev.msg
|
||||||
|
|
@ -47,7 +47,7 @@ func NewCyUpdate(e *event.TypeMuxEvent) (*CyUpdate, error) {
|
||||||
var source, target string
|
var source, target string
|
||||||
source = msg.One.String()
|
source = msg.One.String()
|
||||||
target = msg.Other.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
|
action = ev.Action
|
||||||
} else if ev, ok := entry.(*ConnEvent); ok {
|
} else if ev, ok := entry.(*ConnEvent); ok {
|
||||||
// mutually exclusive directed edge (caller -> callee)
|
// mutually exclusive directed edge (caller -> callee)
|
||||||
|
|
@ -61,7 +61,7 @@ func NewCyUpdate(e *event.TypeMuxEvent) (*CyUpdate, error) {
|
||||||
source = conn.One.String()
|
source = conn.One.String()
|
||||||
target = conn.Other.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
|
action = ev.Action
|
||||||
} else {
|
} else {
|
||||||
return nil, fmt.Errorf("unknown event type: %T", entry)
|
return nil, fmt.Errorf("unknown event type: %T", entry)
|
||||||
|
|
@ -84,10 +84,10 @@ func NewCyUpdate(e *event.TypeMuxEvent) (*CyUpdate, error) {
|
||||||
return &update, nil
|
return &update, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateCy(conf *CyConfig, j *Journal) (*CyUpdate, error) {
|
func UpdateSim(conf *SimConfig, j *Journal) (*SimUpdate, error) {
|
||||||
var update CyUpdate
|
var update SimUpdate
|
||||||
j.Read(func(e *event.TypeMuxEvent) bool {
|
j.Read(func(e *event.TypeMuxEvent) bool {
|
||||||
u, err := NewCyUpdate(e)
|
u, err := NewSimUpdate(e)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err.Error())
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue