// newStreamHandler is the remote-opened stream handler for inet.Network // TODO: this feels a bit wonky func (h *BasicHost) newStreamHandler(s inet.Stream) { protoID, handle, err := h.Mux().Negotiate(s) if err != nil { if err == io.EOF { log.Debugf("protocol EOF: %s", s.Conn().RemotePeer()) } else { log.Warning("protocol mux failed: %s", err) } return } logStream := mstream.WrapStream(s, protocol.ID(protoID), h.bwc) go handle(logStream) }
if err != nil { res.SetError(err, cmds.ErrNormal) return } out := make(chan interface{}) res.SetOutput((<-chan interface{})(out)) go func() { defer close(out) for { if pfound { stats := nd.Reporter.GetBandwidthForPeer(pid) out <- &stats } else if tfound { protoId := protocol.ID(tstr) stats := nd.Reporter.GetBandwidthForProtocol(protoId) out <- &stats } else { totals := nd.Reporter.GetBandwidthTotals() out <- &totals } if !doPoll { return } select { case <-time.After(interval): case <-req.Context().Done(): return } }