Skip to content

Commit

Permalink
Merge pull request #97 from libp2p/feat/signing
Browse files Browse the repository at this point in the history
Implement message signing
  • Loading branch information
vyzo authored Oct 13, 2018
2 parents 4986a90 + 4dc7963 commit 4eb6b7c
Show file tree
Hide file tree
Showing 7 changed files with 432 additions and 70 deletions.
36 changes: 36 additions & 0 deletions floodsub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -899,3 +899,39 @@ func assertPeerList(t *testing.T, peers []peer.ID, expected ...peer.ID) {
}
}
}

func TestWithSigning(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

hosts := getNetHosts(t, ctx, 2)
psubs := getPubsubs(ctx, hosts, WithMessageSigning(true))

connect(t, hosts[0], hosts[1])

topic := "foobar"
data := []byte("this is a message")

sub, err := psubs[1].Subscribe(topic)
if err != nil {
t.Fatal(err)
}

time.Sleep(time.Millisecond * 10)

err = psubs[0].Publish(topic, data)
if err != nil {
t.Fatal(err)
}

msg, err := sub.Next(ctx)
if err != nil {
t.Fatal(err)
}
if msg.Signature == nil {
t.Fatal("no signature in message")
}
if string(msg.Data) != string(data) {
t.Fatalf("unexpected data: %s", string(msg.Data))
}
}
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@
"hash": "QmdxUuburamoF6zF9qjeQC4WYcWGbWuRmdLacMEsW8ioD8",
"name": "gogo-protobuf",
"version": "0.0.0"
},
{
"author": "whyrusleeping",
"hash": "QmPvyPwuCgJ7pDmrKDxRtsScJgBaM5h4EpRL2qQJsmXf4n",
"name": "go-libp2p-crypto",
"version": "2.0.1"
}
],
"gxVersion": "0.9.0",
Expand Down
207 changes: 153 additions & 54 deletions pb/rpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pb/rpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ message Message {
optional bytes data = 2;
optional bytes seqno = 3;
repeated string topicIDs = 4;
optional bytes signature = 5;
optional bytes key = 6;
}

message ControlMessage {
Expand Down
Loading

0 comments on commit 4eb6b7c

Please sign in to comment.