Skip to content
This repository has been archived by the owner on Sep 6, 2022. It is now read-only.

Signed envelopes & routing records #73

Merged
merged 70 commits into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from 66 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
f4c9da5
add SignedEnvelope type
yusefnapora Nov 6, 2019
133f891
use struct for SignedEnvelope instead of exposing protobuf directly
yusefnapora Nov 7, 2019
cc866a8
doc comments for envelopes
yusefnapora Nov 7, 2019
71be7ba
tests for SignedEnvelopes
yusefnapora Nov 7, 2019
8d61036
add routing state records, extend peerstore API
yusefnapora Dec 20, 2019
791e33f
add helpers to make routing records for Host
yusefnapora Nov 8, 2019
2ebfd9d
fix doc comment
yusefnapora Nov 8, 2019
c016eb5
go fmt
yusefnapora Nov 8, 2019
f01458e
add method to peerstore to retrieve signed routing records
yusefnapora Nov 8, 2019
d75c257
update to match spec changes
yusefnapora Nov 11, 2019
f583d3c
just use nanoseconds
yusefnapora Nov 11, 2019
cf0cfa5
use proto3 & rename fields to match spec changes
yusefnapora Nov 15, 2019
a8a530e
use proto3 for routing records
yusefnapora Nov 15, 2019
3724a31
make envelope fields private & validate on unmarshal
yusefnapora Nov 15, 2019
be36d83
use buffer pool for envelope signatures
yusefnapora Nov 18, 2019
7d10658
tests for RoutingState
yusefnapora Nov 18, 2019
c8a9a5e
go fmt
yusefnapora Nov 18, 2019
cf19665
rename Equals -> Equal, add some comments
yusefnapora Nov 19, 2019
a56dc2c
use test helpers
yusefnapora Nov 19, 2019
bf36932
get rid of unsigned RoutingState struct, only expose SignedRoutingState
yusefnapora Nov 21, 2019
00306a4
rm batching SignedRoutingStates accessor in peerstore
yusefnapora Nov 21, 2019
347316f
whitespace
yusefnapora Nov 21, 2019
272731b
expose struct fields & remove accessors
yusefnapora Nov 21, 2019
ff5ddb3
use multiformats uvarint for length-prefixes
yusefnapora Dec 9, 2019
fb521c6
use camelCase in protos for consistency
yusefnapora Nov 25, 2019
305fff1
fix: rebuild protos with new gogofaster generator
yusefnapora Dec 20, 2019
ae469c6
remove payloadType check when unmarhaling
yusefnapora Dec 9, 2019
1168b4d
rm stray ref to golang/protobuf
yusefnapora Dec 9, 2019
74bb6bb
filter private addrs from signed routing records
yusefnapora Dec 20, 2019
8a8390e
add events for updated addresses and routing state
yusefnapora Dec 20, 2019
0bcca67
remove SignedRoutingStateFromHost helper
yusefnapora Dec 20, 2019
6028ba0
envelope: use byte slices from pool; adjust interface.
raulk Dec 27, 2019
123324d
move envelope to record package.
raulk Dec 27, 2019
bb547ef
move protobuf files; adjust imports everywhere.
raulk Dec 27, 2019
ae465aa
define CertifiedAddrBook to avoid breaking API change
yusefnapora Dec 13, 2019
2e8cabc
rename RoutingStateRecord -> PeerRecord
yusefnapora Jan 7, 2020
59348de
test that PeerRecords can't be signed by wrong key
yusefnapora Jan 7, 2020
5f6b601
hoist Seq from PeerRecord to SignedEnvelope
yusefnapora Jan 7, 2020
25c1a5d
commit go.sum
yusefnapora Jan 7, 2020
ce6885c
add Seq field to envelope signature
yusefnapora Jan 7, 2020
be3fa5f
fix proto_path in Makefile
yusefnapora Jan 15, 2020
4b29ab4
fix import ordering
yusefnapora Jan 15, 2020
1ff5578
comments for PeerRecord proto message
yusefnapora Jan 15, 2020
8dc249d
use Record type for envelope payloads
yusefnapora Jan 15, 2020
77a03aa
rename SignedEnvelope -> Envelope, unmarshal payload in ConsumeEnvelope
yusefnapora Jan 16, 2020
8d8da38
return buffer to pool before early return
yusefnapora Jan 16, 2020
39d8cbc
doc comments
yusefnapora Jan 16, 2020
d567b24
rename CertifiedAddrBook methods, update comments
yusefnapora Jan 17, 2020
cf0122a
cache unmarshalled Record payload inside Envelope
yusefnapora Jan 17, 2020
9724544
doc comments
yusefnapora Jan 17, 2020
7ee4611
store reflect.Type when registering Record
yusefnapora Jan 17, 2020
3c208b0
Revert "return buffer to pool before early return"
yusefnapora Jan 17, 2020
a26c845
use a DefaultRecord for unregistered PayloadTypes
yusefnapora Jan 17, 2020
ae3bc7b
cleanup DefaultRecord code a bit
yusefnapora Jan 17, 2020
7a05223
use explicit payloadType in MakeEnvelopeWithRecord
yusefnapora Jan 20, 2020
1de3d24
Revert DefaultRecord commits
yusefnapora Jan 20, 2020
b203ce3
doc comments
yusefnapora Jan 20, 2020
25ff074
move Seq field back to PeerRecord
yusefnapora Jan 20, 2020
5a523a1
make diffs optional in EvtLocalAddressesUpdated
yusefnapora Jan 21, 2020
33890dd
more envelope tests
yusefnapora Jan 22, 2020
3e293ba
replace MakeEnvelope with record.Seal
yusefnapora Feb 3, 2020
1a439d7
fix import
yusefnapora Feb 3, 2020
04ce144
add interface check
yusefnapora Feb 3, 2020
c29b681
rename ProcessPeerRecord -> ConsumePeerRecord
yusefnapora Feb 4, 2020
48fdd0f
Merge origin/master into peer-records
yusefnapora Feb 4, 2020
97eee5a
rename event field, add doc comment
yusefnapora Feb 4, 2020
dfb8a63
peer record protobuf: fix field casing.
raulk Feb 10, 2020
4a3c9dd
record protobuf: add docs and fix casing.
raulk Feb 10, 2020
68fa5dc
cleanup: group imports.
raulk Feb 10, 2020
541a648
nit: split test/utils.go => test/{addrs,errors}.go.
raulk Feb 10, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crypto/pb/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ GO = $(PB:.proto=.pb.go)
all: $(GO)

%.pb.go: %.proto
protoc --proto_path=$(GOPATH)/src:. --gogofaster_out=. $<
protoc --proto_path=$(PWD)/../..:. --gogofaster_out=. $<

clean:
rm -f *.pb.go
Expand Down
2 changes: 2 additions & 0 deletions crypto/pb/crypto.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ syntax = "proto2";

package crypto.pb;

option go_package = "github.com/libp2p/go-libp2p-core/crypto/pb";

enum KeyType {
RSA = 0;
Ed25519 = 1;
Expand Down
82 changes: 82 additions & 0 deletions event/addrs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package event

import (
"github.com/libp2p/go-libp2p-core/record"
ma "github.com/multiformats/go-multiaddr"
)

// AddrAction represents an action taken on one of a Host's listen addresses.
// It is used to add context to address change events in EvtLocalAddressesUpdated.
type AddrAction int

const (
// Unknown means that the event producer was unable to determine why the address
// is in the current state.
Unknown AddrAction = iota

// Added means that the address is new and was not present prior to the event.
Added

// Maintained means that the address was not altered between the current and
// previous states.
Maintained

// Removed means that the address was removed from the Host.
Removed
)

// UpdatedAddress is used in the EvtLocalAddressesUpdated event to convey
// address change information.
type UpdatedAddress struct {
// Address contains the address that was updated.
Address ma.Multiaddr

// Action indicates what action was taken on the address during the
// event. May be Unknown if the event producer cannot produce diffs.
Action AddrAction
}

// EvtLocalAddressesUpdated should be emitted when the set of listen addresses for
// the local host changes. This may happen for a number of reasons. For example,
// we may have opened a new relay connection, established a new NAT mapping via
// UPnP, or been informed of our observed address by another peer.
//
// EvtLocalAddressesUpdated contains a snapshot of the current listen addresses,
// and may also contain a diff between the current state and the previous state.
// If the event producer is capable of creating a diff, the Diffs field will be
// true, and event consumers can inspect the Action field of each UpdatedAddress
// to see how each address was modified.
//
// For example, the Action will tell you whether an address in
// the Current list was Added by the event producer, or was Maintained without
// changes. Addresses that were removed from the Host will have the AddrAction
// of Removed, and will be in the Removed list.
//
// If the event producer is not capable or producing diffs, the Diffs field will
// be false, the Removed list will always be empty, and the Action for each
// UpdatedAddress in the Current list will be Unknown.
type EvtLocalAddressesUpdated struct {
yusefnapora marked this conversation as resolved.
Show resolved Hide resolved

// Diffs indicates whether this event contains a diff of the Host's previous
// address set.
Diffs bool

// Current contains all current listen addresses for the Host.
// If Diffs == true, the Action field of each UpdatedAddress will tell
// you whether an address was Added, or was Maintained from the previous
// state.
Current []UpdatedAddress

// Removed contains addresses that were removed from the Host.
// This field is only set when Diffs == true.
Removed []UpdatedAddress
}

// EvtLocalPeerRoutingStateUpdated should be emitted when a new signed PeerRecord
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EvtLocalPeerRecordUpdated*

// for the local peer has been produced. This will happen whenever the set of listen
// addresses changes.
type EvtLocalPeerRecordUpdated struct {
// Record contains the updated peer.PeerRecord, wrapped in a record.Envelope and
// signed by the Host's private key.
Record *record.Envelope
}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ require (
github.com/gogo/protobuf v1.3.1
github.com/ipfs/go-cid v0.0.4
github.com/jbenet/goprocess v0.1.3
github.com/libp2p/go-buffer-pool v0.0.1
github.com/libp2p/go-flow-metrics v0.0.3
github.com/libp2p/go-openssl v0.0.4
github.com/minio/sha256-simd v0.1.1
github.com/mr-tron/base58 v1.1.3
github.com/multiformats/go-multiaddr v0.2.0
github.com/multiformats/go-multihash v0.0.13
github.com/multiformats/go-varint v0.0.5
github.com/smola/gocompat v0.2.0
go.opencensus.io v0.22.2
)
Expand Down
51 changes: 5 additions & 46 deletions go.sum

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions peer/pb/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
PB = $(wildcard *.proto)
GO = $(PB:.proto=.pb.go)

all: $(GO)

%.pb.go: %.proto
protoc --proto_path=$(PWD):$(PWD)/../.. --gogofaster_out=. $<

clean:
rm -f *.pb.go
rm -f *.go
Loading