diff options
Diffstat (limited to 'network/wsPeer.go')
-rw-r--r-- | network/wsPeer.go | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/network/wsPeer.go b/network/wsPeer.go index f9e5e1dc1..f476cfa7e 100644 --- a/network/wsPeer.go +++ b/network/wsPeer.go @@ -90,6 +90,8 @@ type wsPeerWebsocketConn interface { WriteControl(int, []byte, time.Time) error SetReadLimit(int64) CloseWithoutFlush() error + SetPingHandler(h func(appData string) error) + SetPongHandler(h func(appData string) error) } type sendMessage struct { @@ -136,7 +138,7 @@ type wsPeer struct { // lastPacketTime contains the UnixNano at the last time a successful communication was made with the peer. // "successful communication" above refers to either reading from or writing to a connection without receiving any // error. - // we want this to be a 64-bit aligned for atomics. + // we want this to be a 64-bit aligned for atomics support on 32bit platforms. lastPacketTime int64 // intermittentOutgoingMessageEnqueueTime contains the UnixNano of the message's enqueue time that is currently being written to the @@ -418,6 +420,7 @@ func (wp *wsPeer) readLoop() { wp.reportReadErr(err) return } + msg.processing = wp.processed msg.Received = time.Now().UnixNano() msg.Data = slurper.Bytes() @@ -597,12 +600,14 @@ func (wp *wsPeer) writeLoopSendMsg(msg sendMessage) disconnectReason { } // check if this message was waiting in the queue for too long. If this is the case, return "true" to indicate that we want to close the connection. - msgWaitDuration := time.Now().Sub(msg.enqueued) + now := time.Now() + msgWaitDuration := now.Sub(msg.enqueued) if msgWaitDuration > maxMessageQueueDuration { wp.net.log.Warnf("peer stale enqueued message %dms", msgWaitDuration.Nanoseconds()/1000000) networkConnectionsDroppedTotal.Inc(map[string]string{"reason": "stale message"}) return disconnectStaleWrite } + atomic.StoreInt64(&wp.intermittentOutgoingMessageEnqueueTime, msg.enqueued.UnixNano()) defer atomic.StoreInt64(&wp.intermittentOutgoingMessageEnqueueTime, 0) err := wp.conn.WriteMessage(websocket.BinaryMessage, msg.data) |