code: func (net *Network) watchPeerEvents(id enode.ID, events chan *p2p.PeerEvent, sub event.Subscription) {
  	defer func() {
  		sub.Unsubscribe()
  
  		// assume the node is now down
  		net.lock.Lock()
  		defer net.lock.Unlock()
  
  		node := net.getNode(id)
  		if node == nil {
  			return
  		}
  		node.SetUp(false)
  		ev := NewEvent(node)
  		net.events.Send(ev)
  	}()
  	for {
  		select {
  		case event, ok := <-events:
  			if !ok {
  				return
  			}
  			peer := event.Peer
  			switch event.Type {
  
  			case p2p.PeerEventTypeAdd:
  				net.DidConnect(id, peer)
  
  			case p2p.PeerEventTypeDrop:
  				net.DidDisconnect(id, peer)
  
  			case p2p.PeerEventTypeMsgSend:
  				net.DidSend(id, peer, event.Protocol, *event.MsgCode)
  
  			case p2p.PeerEventTypeMsgRecv:
  				net.DidReceive(peer, id, event.Protocol, *event.MsgCode)
  
  			}
  
  		case err := <-sub.Err():
  			if err != nil {
  				log.Error("Error in peer event subscription", "id", id, "err", err)
  			}
  			return
  		}
  	}
  }
docs: // watchPeerEvents reads peer events from the given channel and emits
  // corresponding network events