Skip to content

Commit

Permalink
Merge pull request #5346 from joostjager/custom-messages
Browse files Browse the repository at this point in the history
lnrpc+peer: custom peer messages
  • Loading branch information
Roasbeef committed Oct 19, 2021
2 parents 94b7b71 + ade50d0 commit e6c65f1
Show file tree
Hide file tree
Showing 18 changed files with 5,035 additions and 3,839 deletions.
83 changes: 83 additions & 0 deletions cmd/lncli/cmd_custom.go
@@ -0,0 +1,83 @@
package main

import (
"encoding/hex"
"fmt"

"github.com/lightningnetwork/lnd/lnrpc"
"github.com/urfave/cli"
)

var sendCustomCommand = cli.Command{
Name: "sendcustom",
Flags: []cli.Flag{
cli.StringFlag{
Name: "peer",
},
cli.Uint64Flag{
Name: "type",
},
cli.StringFlag{
Name: "data",
},
},
Action: actionDecorator(sendCustom),
}

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

peer, err := hex.DecodeString(ctx.String("peer"))
if err != nil {
return err
}

msgType := ctx.Uint64("type")

data, err := hex.DecodeString(ctx.String("data"))
if err != nil {
return err
}

_, err = client.SendCustomMessage(
ctxc,
&lnrpc.SendCustomMessageRequest{
Peer: peer,
Type: uint32(msgType),
Data: data,
},
)

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)
}
}
2 changes: 2 additions & 0 deletions cmd/lncli/main.go
Expand Up @@ -385,6 +385,8 @@ func main() {
profileSubCommand,
getStateCommand,
deletePaymentsCommand,
sendCustomCommand,
subscribeCustomCommand,
}

// Add any extra commands determined by build flags.
Expand Down
19 changes: 18 additions & 1 deletion docs/release-notes/release-notes-0.14.0.md
Expand Up @@ -212,7 +212,23 @@ If you use a strange system or changed group membership of the group running LND
you may want to check your system to see if it introduces additional risk for
you.

## Safety
## 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
their time lock has fully matured](https://github.com/lightningnetwork/lnd/pull/5528).
Expand Down Expand Up @@ -511,6 +527,7 @@ change](https://github.com/lightningnetwork/lnd/pull/5613).
* Hampus Sjöberg
* Harsha Goli
* Jesse de Wit
* Joost Jager
* Martin Habovstiak
* Naveen Srinivasan
* Oliver Gugger
Expand Down

0 comments on commit e6c65f1

Please sign in to comment.