watchtower/wtwire: add DeleteSession and DeleteSessionReply message
This commit is contained in:
parent
6d3b142f2a
commit
3d934d0978
45
watchtower/wtwire/delete_session.go
Normal file
45
watchtower/wtwire/delete_session.go
Normal file
@ -0,0 +1,45 @@
|
||||
package wtwire
|
||||
|
||||
import "io"
|
||||
|
||||
// DeleteSession is sent from the client to the tower to signal that the tower
|
||||
// can delete all session state for the session key used to authenticate the
|
||||
// brontide connection. This should be done by the client once all channels that
|
||||
// have state updates in the session have been resolved on-chain.
|
||||
type DeleteSession struct{}
|
||||
|
||||
// Compile-time constraint to ensure DeleteSession implements the wtwire.Message
|
||||
// interface.
|
||||
var _ Message = (*DeleteSession)(nil)
|
||||
|
||||
// Decode deserializes a serialized DeleteSession message stored in the passed
|
||||
// io.Reader observing the specified protocol version.
|
||||
//
|
||||
// This is part of the wtwire.Message interface.
|
||||
func (m *DeleteSession) Decode(r io.Reader, pver uint32) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Encode serializes the target DeleteSession message into the passed io.Writer
|
||||
// observing the specified protocol version.
|
||||
//
|
||||
// This is part of the wtwire.Message interface.
|
||||
func (m *DeleteSession) Encode(w io.Writer, pver uint32) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// MsgType returns the integer uniquely identifying this message type on the
|
||||
// wire.
|
||||
//
|
||||
// This is part of the wtwire.Message interface.
|
||||
func (m *DeleteSession) MsgType() MessageType {
|
||||
return MsgDeleteSession
|
||||
}
|
||||
|
||||
// MaxPayloadLength returns the maximum allowed payload size for a DeleteSession
|
||||
// message observing the specified protocol version.
|
||||
//
|
||||
// This is part of the wtwire.Message interface.
|
||||
func (m *DeleteSession) MaxPayloadLength(uint32) uint32 {
|
||||
return 0
|
||||
}
|
66
watchtower/wtwire/delete_session_reply.go
Normal file
66
watchtower/wtwire/delete_session_reply.go
Normal file
@ -0,0 +1,66 @@
|
||||
package wtwire
|
||||
|
||||
import "io"
|
||||
|
||||
// DeleteSessionCode is an error code returned by a watchtower in response to a
|
||||
// DeleteSession message.
|
||||
type DeleteSessionCode = ErrorCode
|
||||
|
||||
const (
|
||||
// DeleteSessionCodeNotFound is returned when the watchtower does not
|
||||
// know of the requested session. This may indicate an error on the
|
||||
// client side, or that the tower had already deleted the session in a
|
||||
// prior request that the client may not have received.
|
||||
DeleteSessionCodeNotFound DeleteSessionCode = 80
|
||||
|
||||
// TODO(conner): add String method after wtclient is merged
|
||||
)
|
||||
|
||||
// DeleteSessionReply is a message sent in response to a client's DeleteSession
|
||||
// request. The message indicates whether or not the deletion was a success or
|
||||
// failure.
|
||||
type DeleteSessionReply struct {
|
||||
// Code will be non-zero if the watchtower was not able to delete the
|
||||
// requested session.
|
||||
Code DeleteSessionCode
|
||||
}
|
||||
|
||||
// A compile time check to ensure DeleteSessionReply implements the
|
||||
// wtwire.Message interface.
|
||||
var _ Message = (*DeleteSessionReply)(nil)
|
||||
|
||||
// Decode deserializes a serialized DeleteSessionReply message stored in the
|
||||
// passed io.Reader observing the specified protocol version.
|
||||
//
|
||||
// This is part of the wtwire.Message interface.
|
||||
func (m *DeleteSessionReply) Decode(r io.Reader, pver uint32) error {
|
||||
return ReadElements(r,
|
||||
&m.Code,
|
||||
)
|
||||
}
|
||||
|
||||
// Encode serializes the target DeleteSessionReply into the passed io.Writer
|
||||
// observing the protocol version specified.
|
||||
//
|
||||
// This is part of the wtwire.Message interface.
|
||||
func (m *DeleteSessionReply) Encode(w io.Writer, pver uint32) error {
|
||||
return WriteElements(w,
|
||||
m.Code,
|
||||
)
|
||||
}
|
||||
|
||||
// MsgType returns the integer uniquely identifying this message type on the
|
||||
// wire.
|
||||
//
|
||||
// This is part of the wtwire.Message interface.
|
||||
func (m *DeleteSessionReply) MsgType() MessageType {
|
||||
return MsgDeleteSessionReply
|
||||
}
|
||||
|
||||
// MaxPayloadLength returns the maximum allowed payload size for a
|
||||
// DeleteSessionReply complete message observing the specified protocol version.
|
||||
//
|
||||
// This is part of the wtwire.Message interface.
|
||||
func (m *DeleteSessionReply) MaxPayloadLength(uint32) uint32 {
|
||||
return 2
|
||||
}
|
@ -40,6 +40,13 @@ const (
|
||||
|
||||
// MsgStateUpdateReply identifies an encoded StateUpdateReply message.
|
||||
MsgStateUpdateReply MessageType = 305
|
||||
|
||||
// MsgDeleteSession identifies an encoded DeleteSession message.
|
||||
MsgDeleteSession MessageType = 306
|
||||
|
||||
// MsgDeleteSessionReply identifies an encoded DeleteSessionReply
|
||||
// message.
|
||||
MsgDeleteSessionReply MessageType = 307
|
||||
)
|
||||
|
||||
// String returns a human readable description of the message type.
|
||||
@ -55,6 +62,10 @@ func (m MessageType) String() string {
|
||||
return "MsgStateUpdate"
|
||||
case MsgStateUpdateReply:
|
||||
return "MsgStateUpdateReply"
|
||||
case MsgDeleteSession:
|
||||
return "MsgDeleteSession"
|
||||
case MsgDeleteSessionReply:
|
||||
return "MsgDeleteSessionReply"
|
||||
case MsgError:
|
||||
return "Error"
|
||||
default:
|
||||
@ -97,6 +108,10 @@ func makeEmptyMessage(msgType MessageType) (Message, error) {
|
||||
msg = &StateUpdate{}
|
||||
case MsgStateUpdateReply:
|
||||
msg = &StateUpdateReply{}
|
||||
case MsgDeleteSession:
|
||||
msg = &DeleteSession{}
|
||||
case MsgDeleteSessionReply:
|
||||
msg = &DeleteSessionReply{}
|
||||
case MsgError:
|
||||
msg = &Error{}
|
||||
default:
|
||||
|
@ -126,6 +126,18 @@ func TestWatchtowerWireProtocol(t *testing.T) {
|
||||
return mainScenario(&m)
|
||||
},
|
||||
},
|
||||
{
|
||||
msgType: wtwire.MsgDeleteSession,
|
||||
scenario: func(m wtwire.DeleteSession) bool {
|
||||
return mainScenario(&m)
|
||||
},
|
||||
},
|
||||
{
|
||||
msgType: wtwire.MsgDeleteSessionReply,
|
||||
scenario: func(m wtwire.DeleteSessionReply) bool {
|
||||
return mainScenario(&m)
|
||||
},
|
||||
},
|
||||
{
|
||||
msgType: wtwire.MsgError,
|
||||
scenario: func(m wtwire.Error) bool {
|
||||
|
Loading…
Reference in New Issue
Block a user