github.com/decred/dcrlnd@v0.7.6/watchtower/wtwire/state_update_reply.go (about) 1 package wtwire 2 3 import "io" 4 5 // StateUpdateCode is an error code returned by a watchtower in response to a 6 // StateUpdate message. 7 type StateUpdateCode = ErrorCode 8 9 const ( 10 // StateUpdateCodeClientBehind signals that the client's sequence number 11 // is behind what the watchtower expects based on its LastApplied. This 12 // error should cause the client to record the LastApplied field in the 13 // response, and initiate another attempt with the proper sequence 14 // number. 15 // 16 // NOTE: Repeated occurrences of this could be interpreted as an attempt 17 // to siphon state updates from the client. If the client believes it 18 // is not violating the protocol, this could be grounds to blacklist 19 // this tower from future session negotiation. 20 StateUpdateCodeClientBehind StateUpdateCode = 70 21 22 // StateUpdateCodeMaxUpdatesExceeded signals that the client tried to 23 // send a sequence number beyond the negotiated MaxUpdates of the 24 // session. 25 StateUpdateCodeMaxUpdatesExceeded StateUpdateCode = 71 26 27 // StateUpdateCodeSeqNumOutOfOrder signals the client sent an update 28 // that does not follow the required incremental monotonicity required 29 // by the tower. 30 StateUpdateCodeSeqNumOutOfOrder StateUpdateCode = 72 31 ) 32 33 // StateUpdateReply is a message sent from watchtower to client in response to a 34 // StateUpdate message, and signals either an acceptance or rejection of the 35 // proposed state update. 36 type StateUpdateReply struct { 37 // Code will be non-zero if the watchtower rejected the state update. 38 Code StateUpdateCode 39 40 // LastApplied returns the sequence number of the last accepted update 41 // known to the watchtower. If the update was successful, this value 42 // should be the sequence number of the last update sent. 43 LastApplied uint16 44 } 45 46 // A compile time check to ensure StateUpdateReply implements the wtwire.Message 47 // interface. 48 var _ Message = (*StateUpdateReply)(nil) 49 50 // Decode deserializes a serialized StateUpdateReply message stored in the passed 51 // io.Reader observing the specified protocol version. 52 // 53 // This is part of the wtwire.Message interface. 54 func (t *StateUpdateReply) Decode(r io.Reader, pver uint32) error { 55 return ReadElements(r, 56 &t.Code, 57 &t.LastApplied, 58 ) 59 } 60 61 // Encode serializes the target StateUpdateReply into the passed io.Writer 62 // observing the protocol version specified. 63 // 64 // This is part of the wtwire.Message interface. 65 func (t *StateUpdateReply) Encode(w io.Writer, pver uint32) error { 66 return WriteElements(w, 67 t.Code, 68 t.LastApplied, 69 ) 70 } 71 72 // MsgType returns the integer uniquely identifying this message type on the 73 // wire. 74 // 75 // This is part of the wtwire.Message interface. 76 func (t *StateUpdateReply) MsgType() MessageType { 77 return MsgStateUpdateReply 78 } 79 80 // MaxPayloadLength returns the maximum allowed payload size for a 81 // StateUpdateReply complete message observing the specified protocol version. 82 // 83 // This is part of the wtwire.Message interface. 84 func (t *StateUpdateReply) MaxPayloadLength(uint32) uint32 { 85 return 4 86 }