From a92a34145016dc7e4030290e98ef8f414ffe7e97 Mon Sep 17 00:00:00 2001 From: Lewis Marshall Date: Mon, 5 Jun 2017 10:14:00 +0100 Subject: [PATCH] p2p/simulations: Add external networks to HTTP server Signed-off-by: Lewis Marshall --- p2p/simulations/http.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/p2p/simulations/http.go b/p2p/simulations/http.go index 1b86fca438..0d1742cfaf 100644 --- a/p2p/simulations/http.go +++ b/p2p/simulations/http.go @@ -255,6 +255,10 @@ type ServerConfig struct { // network NewAdapter func() adapters.NodeAdapter + // ExternalNetworks are externally defined networks to expose via the + // HTTP server + ExternalNetworks map[string]*Network + // Mocker is the function which will be called when a client sends a // POST request to /networks//mock and is expected to // generate some mock events in the network @@ -286,6 +290,9 @@ func NewServer(config *ServerConfig) *Server { router: httprouter.New(), networks: make(map[string]*Network), } + for name, network := range config.ExternalNetworks { + s.networks[name] = network + } s.OPTIONS("/networks", s.Options) s.POST("/networks", s.CreateNetwork)