Add ability to choose propagation algorithm
This commit is contained in:
parent
a86623ef94
commit
7d4ace2b59
File diff suppressed because it is too large
Load Diff
|
@ -11,6 +11,7 @@ import (
|
|||
|
||||
// SimulationRequests defines a POST request payload for simulation backend.
|
||||
type SimulationRequest struct {
|
||||
Algorithm string `json:"algorithm"`
|
||||
SenderIdx int `json:"senderIdx"` // index of the sender node (index of data.Nodes, in fact)
|
||||
TTL int `json:"ttl"` // ttl in seconds
|
||||
MsgSize int `json:"msg_size"` // msg size in bytes
|
||||
|
@ -46,8 +47,14 @@ func simulationHandler(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
algo := "whisperv6"
|
||||
if req.Algorithm == "gossip" {
|
||||
algo = "gossip"
|
||||
} // TODO: add proper validation for algorithm
|
||||
log.Printf("Using %s propagation algorithm", algo)
|
||||
|
||||
log.Printf("Loaded graph with %d nodes", network.NumNodes())
|
||||
sim := NewSimulation(network)
|
||||
sim := NewSimulation(algo, network)
|
||||
sim.Start(req.SenderIdx, req.TTL, req.MsgSize)
|
||||
defer sim.Stop()
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
"github.com/divan/graphx/graph"
|
||||
"github.com/status-im/simulation/propagation"
|
||||
"github.com/status-im/simulation/propagation/gossip"
|
||||
"github.com/status-im/simulation/propagation/whisperv6"
|
||||
)
|
||||
|
||||
|
@ -19,8 +20,13 @@ type Simulation struct {
|
|||
}
|
||||
|
||||
// NewSimulation creates Simulation for the given network.
|
||||
func NewSimulation(network *graph.Graph) *Simulation {
|
||||
sim := whisperv6.NewSimulator(network)
|
||||
func NewSimulation(algo string, network *graph.Graph) *Simulation {
|
||||
var sim propagation.Simulator
|
||||
if algo == "whisperv6" {
|
||||
sim = whisperv6.NewSimulator(network)
|
||||
} else {
|
||||
sim = gossip.NewSimulator(network, 4, 10)
|
||||
}
|
||||
|
||||
return &Simulation{
|
||||
network: network,
|
||||
|
|
|
@ -17,6 +17,7 @@ func main() {
|
|||
gethlogLevel = flag.String("loglevel", "crit", "Geth log level for whisper simulator (crti, error, warn, info, debug, trace)")
|
||||
ttl = flag.Int("ttl", 10, "TTL for generated messages")
|
||||
size = flag.Int("msgSize", 400, "Payload size for generated messages")
|
||||
algorithm = flag.String("algorithm", "whisperv6", "Propagation algorithm to use (whisperv6, gossip)")
|
||||
)
|
||||
flag.Parse()
|
||||
|
||||
|
@ -28,7 +29,13 @@ func main() {
|
|||
}
|
||||
log.Printf("Loaded network graph from %s file", *input)
|
||||
|
||||
sim := NewSimulation(data)
|
||||
algo := "whisperv6"
|
||||
if *algorithm == "gossip" {
|
||||
algo = "gossip"
|
||||
} // TODO: add proper validation for algorithm
|
||||
log.Printf("Using %s propagation algorithm", algo)
|
||||
|
||||
sim := NewSimulation(algo, data)
|
||||
log.Printf("Starting message sending simulation for graph with %d nodes...", len(data.Nodes()))
|
||||
sim.Start(*ttl, *size)
|
||||
defer sim.Stop()
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
"github.com/divan/graphx/graph"
|
||||
"github.com/status-im/simulation/propagation"
|
||||
"github.com/status-im/simulation/propagation/gossip"
|
||||
"github.com/status-im/simulation/propagation/whisperv6"
|
||||
)
|
||||
|
||||
|
@ -19,8 +20,13 @@ type Simulation struct {
|
|||
}
|
||||
|
||||
// NewSimulation creates Simulation for the given network.
|
||||
func NewSimulation(network *graph.Graph) *Simulation {
|
||||
sim := whisperv6.NewSimulator(network)
|
||||
func NewSimulation(algo string, network *graph.Graph) *Simulation {
|
||||
var sim propagation.Simulator
|
||||
if algo == "whisperv6" {
|
||||
sim = whisperv6.NewSimulator(network)
|
||||
} else {
|
||||
sim = gossip.NewSimulator(network, 4, 10)
|
||||
}
|
||||
|
||||
return &Simulation{
|
||||
network: network,
|
||||
|
|
Loading…
Reference in New Issue