Skip to content

Commit

Permalink
lnrpc: receive custom message
Browse files Browse the repository at this point in the history
  • Loading branch information
joostjager committed Aug 17, 2021
1 parent bfab1c0 commit 873a520
Show file tree
Hide file tree
Showing 16 changed files with 4,118 additions and 3,548 deletions.
30 changes: 30 additions & 0 deletions cmd/lncli/cmd_custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"encoding/hex"
"fmt"

"github.com/lightningnetwork/lnd/lnrpc"
"github.com/urfave/cli"
Expand Down Expand Up @@ -51,3 +52,32 @@ func sendCustom(ctx *cli.Context) error {

return err
}

var subscribeCustomCommand = cli.Command{
Name: "subscribecustom",
Action: actionDecorator(subscribeCustom),
}

func subscribeCustom(ctx *cli.Context) error {
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()

stream, err := client.SubscribeCustomMessages(
ctxc,
&lnrpc.SubscribeCustomMessagesRequest{},
)
if err != nil {
return err
}

for {
msg, err := stream.Recv()
if err != nil {
return err
}

fmt.Printf("Received from peer %x: type=%d, data=%x\n",
msg.Peer, msg.Type, msg.Data)
}
}
1 change: 1 addition & 0 deletions cmd/lncli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ func main() {
profileSubCommand,
getStateCommand,
sendCustomCommand,
subscribeCustomCommand,
}

// Add any extra commands determined by build flags.
Expand Down
17 changes: 17 additions & 0 deletions docs/release-notes/release-notes-0.14.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@ you.
* [Makes publishtransaction, in the wallet sub-server, reachable through
lncli](https://github.com/lightningnetwork/lnd/pull/5460).

## Custom peer messages

Lightning nodes have a connection to each of their peers for exchanging
messages. In regular operation, these messages coordinate processes such as
channel opening and payment forwarding.

The lightning spec however also defines a custom range (>= 32768) for
experimental and application-specific peer messages.

With this release, [custom peer message
exchange](https://github.com/lightningnetwork/lnd/pull/5346) is added to open up
a range of new possibilities. Custom peer messages allow the lightning protocol
with its transport mechanisms (including tor) and public key authentication to
be leveraged for application-level communication. Note that peers exchange these
messages directly. There is no routing/path finding involved.

# Safety

* Locally force closed channels are now [kept in the channel.backup file until
Expand Down Expand Up @@ -152,6 +168,7 @@ change](https://github.com/lightningnetwork/lnd/pull/5613).
* Andras Banki-Horvath
* ErikEk
* Eugene Siegel
* Joost Jager
* Martin Habovstiak
* Zero-1729
* Oliver Gugger
Expand Down
Loading

0 comments on commit 873a520

Please sign in to comment.