p2p/simulations: Add external networks to HTTP server

Signed-off-by: Lewis Marshall <lewis@lmars.net>
This commit is contained in:
Lewis Marshall 2017-06-05 10:14:00 +01:00
parent 177e720b08
commit a92a341450

View file

@ -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/<netid>/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)