peer: switch to new WriteMessage/ReadMessage after wire msg changes
This commit is contained in:
parent
0ab1c47d31
commit
f867252139
20
peer.go
20
peer.go
@ -271,7 +271,7 @@ func (p *peer) Start() error {
|
|||||||
readErr := make(chan error, 1)
|
readErr := make(chan error, 1)
|
||||||
msgChan := make(chan lnwire.Message, 1)
|
msgChan := make(chan lnwire.Message, 1)
|
||||||
go func() {
|
go func() {
|
||||||
msg, _, err := p.readNextMessage()
|
msg, err := p.readNextMessage()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
readErr <- err
|
readErr <- err
|
||||||
msgChan <- nil
|
msgChan <- nil
|
||||||
@ -372,19 +372,19 @@ func (p *peer) String() string {
|
|||||||
|
|
||||||
// readNextMessage reads, and returns the next message on the wire along with
|
// readNextMessage reads, and returns the next message on the wire along with
|
||||||
// any additional raw payload.
|
// any additional raw payload.
|
||||||
func (p *peer) readNextMessage() (lnwire.Message, []byte, error) {
|
func (p *peer) readNextMessage() (lnwire.Message, error) {
|
||||||
// TODO(roasbeef): use our own net magic?
|
// TODO(roasbeef): should take diff of what was read
|
||||||
n, nextMsg, rawPayload, err := lnwire.ReadMessage(p.conn, 0,
|
// * also switch to message oriented reading
|
||||||
p.addr.ChainNet)
|
n, nextMsg, err := lnwire.ReadMessage(p.conn, 0)
|
||||||
atomic.AddUint64(&p.bytesReceived, uint64(n))
|
atomic.AddUint64(&p.bytesReceived, uint64(n))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(roasbeef): add message summaries
|
// TODO(roasbeef): add message summaries
|
||||||
p.logWireMessage(nextMsg, true)
|
p.logWireMessage(nextMsg, true)
|
||||||
|
|
||||||
return nextMsg, rawPayload, nil
|
return nextMsg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// readHandler is responsible for reading messages off the wire in series, then
|
// readHandler is responsible for reading messages off the wire in series, then
|
||||||
@ -397,7 +397,7 @@ func (p *peer) readHandler() {
|
|||||||
|
|
||||||
out:
|
out:
|
||||||
for atomic.LoadInt32(&p.disconnect) == 0 {
|
for atomic.LoadInt32(&p.disconnect) == 0 {
|
||||||
nextMsg, _, err := p.readNextMessage()
|
nextMsg, err := p.readNextMessage()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
peerLog.Infof("unable to read message from %v: %v",
|
peerLog.Infof("unable to read message from %v: %v",
|
||||||
p, err)
|
p, err)
|
||||||
@ -470,7 +470,7 @@ out:
|
|||||||
isChanUpdate = true
|
isChanUpdate = true
|
||||||
targetChan = msg.ChanID
|
targetChan = msg.ChanID
|
||||||
|
|
||||||
case *lnwire.ChannelUpdateAnnouncement,
|
case *lnwire.ChannelUpdate,
|
||||||
*lnwire.ChannelAnnouncement,
|
*lnwire.ChannelAnnouncement,
|
||||||
*lnwire.NodeAnnouncement,
|
*lnwire.NodeAnnouncement,
|
||||||
*lnwire.AnnounceSignatures:
|
*lnwire.AnnounceSignatures:
|
||||||
@ -586,7 +586,7 @@ func (p *peer) writeMessage(msg lnwire.Message) error {
|
|||||||
// TODO(roasbeef): add message summaries
|
// TODO(roasbeef): add message summaries
|
||||||
p.logWireMessage(msg, false)
|
p.logWireMessage(msg, false)
|
||||||
|
|
||||||
n, err := lnwire.WriteMessage(p.conn, msg, 0, p.addr.ChainNet)
|
n, err := lnwire.WriteMessage(p.conn, msg, 0)
|
||||||
atomic.AddUint64(&p.bytesSent, uint64(n))
|
atomic.AddUint64(&p.bytesSent, uint64(n))
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
@ -1101,7 +1101,7 @@ func (r *rpcServer) SendPaymentSync(ctx context.Context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// With the payment completed successfully, we now ave the details of
|
// With the payment completed successfully, we now ave the details of
|
||||||
// the completed payment to the databse for historical record keeping.
|
// the completed payment to the database for historical record keeping.
|
||||||
if err := r.savePayment(route, amt, rHash[:]); err != nil {
|
if err := r.savePayment(route, amt, rHash[:]); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user