github.com/decred/dcrlnd@v0.7.6/watchtower/wtwire/create_session_reply.go (about) 1 package wtwire 2 3 import "io" 4 5 // CreateSessionCode is an error code returned by a watchtower in response to a 6 // CreateSession message. The code directs the client in interpreting the payload 7 // in the reply. 8 type CreateSessionCode = ErrorCode 9 10 const ( 11 // CreateSessionCodeAlreadyExists is returned when a session is already 12 // active for the public key used to connect to the watchtower. The 13 // response includes the serialized reward address in case the original 14 // reply was never received and/or processed by the client. 15 CreateSessionCodeAlreadyExists CreateSessionCode = 60 16 17 // CreateSessionCodeRejectMaxUpdates the tower rejected the maximum 18 // number of state updates proposed by the client. 19 CreateSessionCodeRejectMaxUpdates CreateSessionCode = 61 20 21 // CreateSessionCodeRejectRewardRate the tower rejected the reward rate 22 // proposed by the client. 23 CreateSessionCodeRejectRewardRate CreateSessionCode = 62 24 25 // CreateSessionCodeRejectSweepFeeRate the tower rejected the sweep fee 26 // rate proposed by the client. 27 CreateSessionCodeRejectSweepFeeRate CreateSessionCode = 63 28 29 // CreateSessionCodeRejectBlobType is returned when the tower does not 30 // support the proposed blob type. 31 CreateSessionCodeRejectBlobType CreateSessionCode = 64 32 ) 33 34 // MaxCreateSessionReplyDataLength is the maximum size of the Data payload 35 // returned in a CreateSessionReply message. This does not include the length of 36 // the Data field, which is a varint up to 3 bytes in size. 37 const MaxCreateSessionReplyDataLength = 1024 38 39 // CreateSessionReply is a message sent from watchtower to client in response to a 40 // CreateSession message, and signals either an acceptance or rejection of the 41 // proposed session parameters. 42 type CreateSessionReply struct { 43 // Code will be non-zero if the watchtower rejected the session init. 44 Code CreateSessionCode 45 46 // LastApplied is the tower's last accepted sequence number for the 47 // session. This is useful when the session already exists but the 48 // client doesn't realize it's already used the session, such as after a 49 // restoration. 50 LastApplied uint16 51 52 // Data is a byte slice returned the caller of the message, and is to be 53 // interpreted according to the error Code. When the response is 54 // CreateSessionCodeOK, data encodes the reward address to be included in 55 // any sweep transactions if the reward is not dusty. Otherwise, it may 56 // encode the watchtowers configured parameters for any policy 57 // rejections. 58 Data []byte 59 } 60 61 // A compile time check to ensure CreateSessionReply implements the wtwire.Message 62 // interface. 63 var _ Message = (*CreateSessionReply)(nil) 64 65 // Decode deserializes a serialized CreateSessionReply message stored in the passed 66 // io.Reader observing the specified protocol version. 67 // 68 // This is part of the wtwire.Message interface. 69 func (m *CreateSessionReply) Decode(r io.Reader, pver uint32) error { 70 return ReadElements(r, 71 &m.Code, 72 &m.LastApplied, 73 &m.Data, 74 ) 75 } 76 77 // Encode serializes the target CreateSessionReply into the passed io.Writer 78 // observing the protocol version specified. 79 // 80 // This is part of the wtwire.Message interface. 81 func (m *CreateSessionReply) Encode(w io.Writer, pver uint32) error { 82 return WriteElements(w, 83 m.Code, 84 m.LastApplied, 85 m.Data, 86 ) 87 } 88 89 // MsgType returns the integer uniquely identifying this message type on the 90 // wire. 91 // 92 // This is part of the wtwire.Message interface. 93 func (m *CreateSessionReply) MsgType() MessageType { 94 return MsgCreateSessionReply 95 } 96 97 // MaxPayloadLength returns the maximum allowed payload size for a CreateSessionReply 98 // complete message observing the specified protocol version. 99 // 100 // This is part of the wtwire.Message interface. 101 func (m *CreateSessionReply) MaxPayloadLength(uint32) uint32 { 102 return 2 + 3 + MaxCreateSessionReplyDataLength 103 }