mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
swarm: linting of simulation package
This commit is contained in:
parent
965014df84
commit
bf87fdc3d7
6 changed files with 24 additions and 9 deletions
|
|
@ -43,7 +43,7 @@ func (s *Simulation) SetNodeItem(id discover.NodeID, key interface{}, value inte
|
|||
s.buckets[id].Store(key, value)
|
||||
}
|
||||
|
||||
// NodeItems returns a map of items from all nodes that are all set under the
|
||||
// NodesItems returns a map of items from all nodes that are all set under the
|
||||
// same BucketKey.
|
||||
func (s *Simulation) NodesItems(key interface{}) (values map[discover.NodeID]interface{}) {
|
||||
s.mu.RLock()
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ func (s *Simulation) ConnectNodesStar(id discover.NodeID, ids []discover.NodeID)
|
|||
return nil
|
||||
}
|
||||
|
||||
// ConnectNodesStar connects all nodes in a star topology
|
||||
// ConnectNodesStarPivot connects all nodes in a star topology
|
||||
// with the center at already set pivot node.
|
||||
// If ids argument is nil, all nodes that are up will be connected.
|
||||
func (s *Simulation) ConnectNodesStarPivot(ids []discover.NodeID) (err error) {
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ func (f *PeerEventsFilter) MsgCode(c uint64) *PeerEventsFilter {
|
|||
func (s *Simulation) PeerEvents(ctx context.Context, ids []discover.NodeID, filters ...*PeerEventsFilter) <-chan PeerEvent {
|
||||
eventC := make(chan PeerEvent)
|
||||
|
||||
// wait group to make sure all subscriptons to admin peerEvents are established
|
||||
// wait group to make sure all subscriptions to admin peerEvents are established
|
||||
// before this function returns.
|
||||
var subsWG sync.WaitGroup
|
||||
for _, id := range ids {
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ var (
|
|||
DefaultHTTPSimAddr = ":8888"
|
||||
)
|
||||
|
||||
//`With`(builder) pattern constructor for Simulation to
|
||||
//WithServer implements the builder pattern constructor for Simulation to
|
||||
//start with a HTTP server
|
||||
func (s *Simulation) WithServer(addr string) *Simulation {
|
||||
//assign default addr if nothing provided
|
||||
|
|
@ -46,7 +46,12 @@ func (s *Simulation) WithServer(addr string) *Simulation {
|
|||
Addr: addr,
|
||||
Handler: s.handler,
|
||||
}
|
||||
go s.httpSrv.ListenAndServe()
|
||||
go func() {
|
||||
err := s.httpSrv.ListenAndServe()
|
||||
if err != nil {
|
||||
log.Error("Error starting the HTTP server", "error", err)
|
||||
}
|
||||
}()
|
||||
return s
|
||||
}
|
||||
|
||||
|
|
@ -55,7 +60,7 @@ func (s *Simulation) addSimulationRoutes() {
|
|||
s.handler.POST("/runsim", s.RunSimulation)
|
||||
}
|
||||
|
||||
// StartNetwork starts all nodes in the network
|
||||
// RunSimulation is the actual POST endpoint runner
|
||||
func (s *Simulation) RunSimulation(w http.ResponseWriter, req *http.Request) {
|
||||
log.Debug("RunSimulation endpoint running")
|
||||
s.runC <- struct{}{}
|
||||
|
|
|
|||
|
|
@ -96,7 +96,12 @@ func sendRunSignal(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("Request failed: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
defer func() {
|
||||
err := resp.Body.Close()
|
||||
if err != nil {
|
||||
log.Error("Error closing response body", "err", err)
|
||||
}
|
||||
}()
|
||||
log.Debug("Signal sent")
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("err %s", resp.Status)
|
||||
|
|
|
|||
|
|
@ -195,7 +195,7 @@ func (s *Simulation) AddNodesAndConnectStar(count int, opts ...AddNodeOption) (i
|
|||
return ids, nil
|
||||
}
|
||||
|
||||
//Upload a snapshot
|
||||
//UploadSnapshot uploads a snapshot to the simulation
|
||||
//This method tries to open the json file provided, applies the config to all nodes
|
||||
//and then loads the snapshot into the Simulation network
|
||||
func (s *Simulation) UploadSnapshot(snapshotFile string, opts ...AddNodeOption) error {
|
||||
|
|
@ -203,7 +203,12 @@ func (s *Simulation) UploadSnapshot(snapshotFile string, opts ...AddNodeOption)
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
defer func() {
|
||||
err := f.Close()
|
||||
if err != nil {
|
||||
log.Error("Error closing snapshot file", "err", err)
|
||||
}
|
||||
}()
|
||||
jsonbyte, err := ioutil.ReadAll(f)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
|||
Loading…
Reference in a new issue