code: func (p *Peer) writeMessage(msg wire.Message, enc wire.MessageEncoding) error {
  	// Don't do anything if we're disconnecting.
  	if atomic.LoadInt32(&p.disconnect) != 0 {
  		return nil
  	}
  
  	// Use closures to log expensive operations so they are only run when
  	// the logging level requires it.
  	log.Debugf("%v", newLogClosure(func() string {
  		// Debug summary of message.
  		summary := messageSummary(msg)
  		if len(summary) > 0 {
  			summary = " (" + summary + ")"
  		}
  		return fmt.Sprintf("Sending %v%s to %s", msg.Command(),
  			summary, p)
  	}))
  	log.Tracef("%v", newLogClosure(func() string {
  		return spew.Sdump(msg)
  	}))
  	log.Tracef("%v", newLogClosure(func() string {
  		var buf bytes.Buffer
  		_, err := wire.WriteMessageWithEncodingN(&buf, msg, p.ProtocolVersion(),
  			p.cfg.ChainParams.Net, enc)
  		if err != nil {
  			return err.Error()
  		}
  		return spew.Sdump(buf.Bytes())
  	}))
  
  	// Write the message to the peer.
  	n, err := wire.WriteMessageWithEncodingN(p.conn, msg,
  		p.ProtocolVersion(), p.cfg.ChainParams.Net, enc)
  	atomic.AddUint64(&p.bytesSent, uint64(n))
  	if p.cfg.Listeners.OnWrite != nil {
  		p.cfg.Listeners.OnWrite(p, n, msg, err)
  	}
  	return err
  }
docs: // writeMessage sends a bitcoin message to the peer with logging.