code: func (msm *MultistreamMuxer) Negotiate(rwc io.ReadWriteCloser) (string, HandlerFunc, error) {
  	// Send our protocol ID
  	err := delimWriteBuffered(rwc, []byte(ProtocolID))
  	if err != nil {
  		return "", nil, err
  	}
  
  	line, err := ReadNextToken(rwc)
  	if err != nil {
  		return "", nil, err
  	}
  
  	if line != ProtocolID {
  		rwc.Close()
  		return "", nil, ErrIncorrectVersion
  	}
  
  loop:
  	for {
  		// Now read and respond to commands until they send a valid protocol id
  		tok, err := ReadNextToken(rwc)
  		if err != nil {
  			return "", nil, err
  		}
  
  		switch tok {
  		case "ls":
  			err := msm.Ls(rwc)
  			if err != nil {
  				return "", nil, err
  			}
  		default:
  			h := msm.findHandler(tok)
  			if h == nil {
  				err := delimWriteBuffered(rwc, []byte("na"))
  				if err != nil {
  					return "", nil, err
  				}
  				continue loop
  			}
  
  			err := delimWriteBuffered(rwc, []byte(tok))
  			if err != nil {
  				return "", nil, err
  			}
  
  			// hand off processing to the sub-protocol handler
  			return tok, h.Handle, nil
  		}
  	}
  
  }
docs: // Negotiate performs protocol selection and returns the protocol name and
  // the matching handler function for it (or an error).