@@ -198,6 +198,9 @@ type LightningClient interface {
198
198
RegisterRPCMiddleware (ctx context.Context , middlewareName ,
199
199
customCaveatName string , readOnly bool , timeout time.Duration ,
200
200
intercept InterceptFunction ) (chan error , error )
201
+
202
+ // SendCustomMessage sends a custom message to a peer.
203
+ SendCustomMessage (ctx context.Context , msg CustomMessage ) error
201
204
}
202
205
203
206
// Info contains info about the connected lnd node.
@@ -1076,6 +1079,18 @@ type QueryRoutesResponse struct {
1076
1079
TotalAmtMsat lnwire.MilliSatoshi
1077
1080
}
1078
1081
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
+
1079
1094
var (
1080
1095
// ErrNoRouteFound is returned if we can't find a path with the passed
1081
1096
// parameters.
@@ -3723,3 +3738,22 @@ func (s *lightningClient) RegisterRPCMiddleware(ctx context.Context,
3723
3738
3724
3739
return errChan , nil
3725
3740
}
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