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