From bd7757881816e3bea88084bb78c233569e76eaa2 Mon Sep 17 00:00:00 2001 From: ffranr Date: Wed, 18 Sep 2024 14:58:02 +0100 Subject: [PATCH] rfqmsg: extend IncomingMsg interface with methods MsgPeer and MsgID This modification simplifies incoming message handling in future commits. --- rfqmsg/buy_request.go | 10 ++++++++++ rfqmsg/messages.go | 6 ++++++ rfqmsg/reject.go | 10 ++++++++++ rfqmsg/sell_request.go | 10 ++++++++++ 4 files changed, 36 insertions(+) diff --git a/rfqmsg/buy_request.go b/rfqmsg/buy_request.go index 9a6373699..30b34d633 100644 --- a/rfqmsg/buy_request.go +++ b/rfqmsg/buy_request.go @@ -168,6 +168,16 @@ func (q *BuyRequest) ToWire() (WireMessage, error) { }, nil } +// MsgPeer returns the peer that sent the message. +func (q *BuyRequest) MsgPeer() route.Vertex { + return q.Peer +} + +// MsgID returns the quote request session ID. +func (q *BuyRequest) MsgID() ID { + return q.ID +} + // String returns a human-readable string representation of the message. func (q *BuyRequest) String() string { var groupKeyBytes []byte diff --git a/rfqmsg/messages.go b/rfqmsg/messages.go index 0a3371ba3..15109bfca 100644 --- a/rfqmsg/messages.go +++ b/rfqmsg/messages.go @@ -156,6 +156,12 @@ func WireMsgDataVersionDecoder(r io.Reader, val any, buf *[8]byte, // IncomingMsg is an interface that represents an inbound wire message // that has been received from a peer. type IncomingMsg interface { + // MsgPeer returns the peer that sent the message. + MsgPeer() route.Vertex + + // MsgID returns the quote request session ID. + MsgID() ID + // String returns a human-readable string representation of the message. String() string } diff --git a/rfqmsg/reject.go b/rfqmsg/reject.go index fdf6c9a06..69a1a9ed6 100644 --- a/rfqmsg/reject.go +++ b/rfqmsg/reject.go @@ -243,6 +243,16 @@ func (q *Reject) ToWire() (WireMessage, error) { }, nil } +// MsgPeer returns the peer that sent the message. +func (q *Reject) MsgPeer() route.Vertex { + return q.Peer +} + +// MsgID returns the quote request session ID. +func (q *Reject) MsgID() ID { + return q.ID +} + // String returns a human-readable string representation of the message. func (q *Reject) String() string { return fmt.Sprintf("Reject(id=%x, err_code=%d, err_msg=%s)", diff --git a/rfqmsg/sell_request.go b/rfqmsg/sell_request.go index 38ee806fb..a34fc90e7 100644 --- a/rfqmsg/sell_request.go +++ b/rfqmsg/sell_request.go @@ -174,6 +174,16 @@ func (q *SellRequest) ToWire() (WireMessage, error) { }, nil } +// MsgPeer returns the peer that sent the message. +func (q *SellRequest) MsgPeer() route.Vertex { + return q.Peer +} + +// MsgID returns the quote request session ID. +func (q *SellRequest) MsgID() ID { + return q.ID +} + // String returns a human-readable string representation of the message. func (q *SellRequest) String() string { var groupKeyBytes []byte