code: func (d *requestDistributor) nextRequest() (distPeer, *distReq, time.Duration) {
  	checkedPeers := make(map[distPeer]struct{})
  	elem := d.reqQueue.Front()
  	var (
  		bestPeer distPeer
  		bestReq  *distReq
  		bestWait time.Duration
  		sel      *weightedRandomSelect
  	)
  
  	d.peerLock.RLock()
  	defer d.peerLock.RUnlock()
  
  	for (len(d.peers) > 0 || elem == d.reqQueue.Front()) && elem != nil {
  		req := elem.Value.(*distReq)
  		canSend := false
  		for peer := range d.peers {
  			if _, ok := checkedPeers[peer]; !ok && peer.canQueue() && req.canSend(peer) {
  				canSend = true
  				cost := req.getCost(peer)
  				wait, bufRemain := peer.waitBefore(cost)
  				if wait == 0 {
  					if sel == nil {
  						sel = newWeightedRandomSelect()
  					}
  					sel.update(selectPeerItem{peer: peer, req: req, weight: int64(bufRemain*1000000) + 1})
  				} else {
  					if bestReq == nil || wait < bestWait {
  						bestPeer = peer
  						bestReq = req
  						bestWait = wait
  					}
  				}
  				checkedPeers[peer] = struct{}{}
  			}
  		}
  		next := elem.Next()
  		if !canSend && elem == d.reqQueue.Front() {
  			close(req.sentChn)
  			d.remove(req)
  		}
  		elem = next
  	}
  
  	if sel != nil {
  		c := sel.choose().(selectPeerItem)
  		return c.peer, c.req, 0
  	}
  	return bestPeer, bestReq, bestWait
  }
docs: // nextRequest returns the next possible request from any peer, along with the
  // associated peer and necessary waiting time