Skip to content

Commit

Permalink
rfqmsg: extend IncomingMsg interface with methods MsgPeer and MsgID
Browse files Browse the repository at this point in the history
This modification simplifies incoming message handling in future
commits.
  • Loading branch information
ffranr committed Sep 19, 2024
1 parent e3f531b commit bd77578
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
10 changes: 10 additions & 0 deletions rfqmsg/buy_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions rfqmsg/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 10 additions & 0 deletions rfqmsg/reject.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
10 changes: 10 additions & 0 deletions rfqmsg/sell_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bd77578

Please sign in to comment.