@@ -198,6 +198,9 @@ type LightningClient interface {
198198 RegisterRPCMiddleware (ctx context.Context , middlewareName ,
199199 customCaveatName string , readOnly bool , timeout time.Duration ,
200200 intercept InterceptFunction ) (chan error , error )
201+
202+ // SendCustomMessage sends a custom message to a peer.
203+ SendCustomMessage (ctx context.Context , msg CustomMessage ) error
201204}
202205
203206// Info contains info about the connected lnd node.
@@ -1076,6 +1079,18 @@ type QueryRoutesResponse struct {
10761079 TotalAmtMsat lnwire.MilliSatoshi
10771080}
10781081
1082+ // CustomMessage describes custom messages exchanged with peers.
1083+ type CustomMessage struct {
1084+ // Peer is the peer that the message was exchanged with.
1085+ Peer route.Vertex
1086+
1087+ // MsgType is the protocol message type number for the custom message.
1088+ MsgType uint32
1089+
1090+ // Data is the data exchanged.
1091+ Data []byte
1092+ }
1093+
10791094var (
10801095 // ErrNoRouteFound is returned if we can't find a path with the passed
10811096 // parameters.
@@ -3723,3 +3738,22 @@ func (s *lightningClient) RegisterRPCMiddleware(ctx context.Context,
37233738
37243739 return errChan , nil
37253740}
3741+
3742+ // SendCustomMessage sends a custom message to one of our existing peers. Note
3743+ // that lnd must already be connected to a peer to send it messages.
3744+ func (s * lightningClient ) SendCustomMessage (ctx context.Context ,
3745+ msg CustomMessage ) error {
3746+
3747+ rpcCtx , cancel := context .WithTimeout (ctx , s .timeout )
3748+ defer cancel ()
3749+
3750+ rpcCtx = s .adminMac .WithMacaroonAuth (rpcCtx )
3751+ rpcReq := & lnrpc.SendCustomMessageRequest {
3752+ Peer : msg .Peer [:],
3753+ Type : msg .MsgType ,
3754+ Data : msg .Data ,
3755+ }
3756+
3757+ _ , err := s .client .SendCustomMessage (rpcCtx , rpcReq )
3758+ return err
3759+ }
0 commit comments