Commit Graph

21 Commits

Author SHA1 Message Date
Marten Seemann
d28ef6339a
remove deprecated Bytes method from the Key interface (#204) 2021-07-22 12:18:09 -07:00
Marten Seemann
6cef973b92
remove deprecated functions in the peer package (#205) 2021-07-22 12:17:36 -07:00
Steven Allen
8c04ed1323
feat: add helper functions for working with addr infos (#202)
Specifically, move them _here_ from the peerstore. That way
packages (like the DHT) that currently directly rely on the peerstore,
can just use go-libp2p-core.

Moved from f7f22569f7/peerstore.go (L79-L93)

With some small modifications.
2021-07-21 13:09:49 -07:00
Steven Allen
ef6e277df7
fix: make timestamps strictly increasing (#201)
* fix: make timestamps strictly increasing

On Linux, this is almost always the case. Windows, however, doesn't have
nanosecond accuracy.

We make the timestamp sequence numbers strictly increasing by returning
the last timestamp + 1 where necessary.

* apply code review

Co-authored-by: Marten Seemann <martenseemann@gmail.com>

* use a lock

Co-authored-by: Marten Seemann <martenseemann@gmail.com>
2021-07-16 15:02:22 -07:00
Marten Seemann
ea8b36912f
fix staticcheck errors (#191)
* run go mod tidy

* omit receiver name if unused

* remove unused type testkey in tests

* fix duplicate import of go-multiaddr

* fix use of deprecated peer.IDB58{Encode,Decode}

* use bytes.Equal instead of bytes.Compare

* fix unnecessary assigments to blank identifier

* use time.Until instead of t.Sub(time.Now())

* fix use of deprecated go-multihash.ID

* add missing error check in envelope test

* fix error check in tests
2021-03-30 16:13:36 -07:00
Whyrusleeping
11f3c3ac0c
add a helper function to go directly from a string to an AddrInfo (#184)
* add a helper function to go directly from a string to an AddrInfo

* Update peer/addrinfo.go

Co-authored-by: Will <will.scott@protocol.ai>

Co-authored-by: Will <will.scott@protocol.ai>
2021-02-22 09:55:28 -08:00
Steven Allen
adcd724744
refactor: use a helper type to decode AddrInfo from JSON (#178)
This saves us a bunch of error prone manual decode/encode logic.

Co-authored-by: Marten Seemann <martenseemann@gmail.com>
2021-02-16 12:06:38 -08:00
Vibhav Pant
6690d78eeb
peer: Add PeerRecordFromProtobuf. 2020-03-27 11:24:40 +05:30
Vibhav Pant
075ac7484c
(*PeerRecord.MarshalRecord): Use ToProtobuf() to get protobuf struct 2020-03-25 17:42:49 +05:30
Vibhav Pant
4013be10ed
peer: Add (*PeerRecord).ToProtoBuf to get protobuf equivalent struct 2020-03-25 17:34:36 +05:30
Vasco Santos
43f10f2288 docs: uniform comment sentences 2020-03-03 18:16:38 +01:00
Yusef Napora
7b2888dfdb
Signed envelopes & routing records (#73)
* add SignedEnvelope type

* use struct for SignedEnvelope instead of exposing protobuf directly

* doc comments for envelopes

* tests for SignedEnvelopes

* add helpers to make routing records for Host

* fix doc comment

* go fmt

* add method to peerstore to retrieve signed routing records

* update to match spec changes

* just use nanoseconds

* use proto3  &  rename fields to match spec changes

* use proto3 for routing records

* make envelope fields private & validate on unmarshal

* use buffer pool for envelope signatures

* tests for RoutingState

* go fmt

* rename Equals -> Equal, add some comments

* use test helpers

* get rid of unsigned RoutingState struct, only expose SignedRoutingState

* rm batching SignedRoutingStates accessor in peerstore

the datastore peerstore implementation doesn't support batched reads, so
it's no more efficient to get a bunch of states at once than it
is to call SignedRoutingState multiple times.

* whitespace

* expose struct fields & remove accessors

* use camelCase in protos for consistency

* use multiformats uvarint for length-prefixes

* remove payloadType check when unmarhaling

* rm stray ref to golang/protobuf

* define CertifiedAddrBook to avoid breaking API change

* add events for updated addresses and routing state

* remove SignedRoutingStateFromHost helper

moving this to go-libp2p

* add routing state records, extend peerstore API

* fix: rebuild protos with new gogofaster generator

* filter private addrs from signed routing records

* envelope: use byte slices from pool; adjust interface.

* move envelope to record package.

* move protobuf files; adjust imports everywhere.

* rename RoutingStateRecord -> PeerRecord

also removes embedded reference to Envelope from the record,
as that was confusing.

as a result, the CertifiedAddrBook now accepts/returns
record.SignedEnvelope instead of a specialized type.

* hoist Seq from PeerRecord to SignedEnvelope

* test that PeerRecords can't be signed by wrong key

* commit go.sum

* add Seq field to envelope signature

* fix proto_path in Makefile

* fix import ordering

* comments for PeerRecord proto message

also removes the seq field from PeerMessage proto,
since it was moved to the SignedEnvelope

* use Record type for envelope payloads

* rename SignedEnvelope -> Envelope, unmarshal payload in ConsumeEnvelope

* return buffer to pool before early return

* doc comments

* rename CertifiedAddrBook methods, update comments

* cache unmarshalled Record payload inside Envelope

* doc comments

* store reflect.Type when registering Record

* Revert "return buffer to pool before early return"

8d8da386f2

misread this - unsigned will be nil if there's an
error, so it was right the way it was

* use a DefaultRecord for unregistered PayloadTypes

instead of returning an error if we don't have a registered
Record for a given PayloadType, we can have a catch-all
DefaultRecord type that just preserves the original payload
as a []byte

* cleanup DefaultRecord code a bit

- removes unused error return from blankRecordForPayloadType
- just references instead of copying in DefaultRecord.UnmarshalRecord
  I figure this is likely safe, since we'll be unmarshalling from the
  payload of an Envelope, which shouldn't get altered after it's
  created.

* use explicit payloadType in MakeEnvelopeWithRecord

* Revert DefaultRecord commits

ae3bc7bdfb
a26c845a76

* doc comments

* move Seq field back to PeerRecord

* make diffs optional in EvtLocalAddressesUpdated

* more envelope tests

* replace MakeEnvelope with record.Seal

also:
- add Domain and Codec fields to Record interface

* fix import

* add interface check

* rename ProcessPeerRecord -> ConsumePeerRecord

also, adds bool `accepted` return value

* rename event field, add doc comment

* peer record protobuf: fix field casing.

* record protobuf: add docs and fix casing.

* cleanup: group imports.

* nit: split test/utils.go => test/{addrs,errors}.go.

Co-authored-by: Raúl Kripalani <raul.kripalani@gmail.com>
2020-02-10 14:53:24 -05:00
Steven Allen
dc718fa4da feat: support encoding/decoding peer IDs as CIDs _in text_ 2019-10-02 08:45:33 -07:00
Cole Brown
d50ea9bc1f Ensure all tests pass without weak RSA key flag 2019-08-28 11:34:22 -04:00
Alex Stokes
686c1736fd
Compare multihash Code to IDENTITY when extracting public key
This PR is a non-substantive change with the goal of making this method
`ExtractPublicKey` from a `peer.ID` clearer to the reader. This goal is
accomplished by using the full name of the identity hash code `IDENTITY` instead
of the deprecated `ID` code. This change makes its clearer to the reader that
there is a trivial way to compute the public key given the digest. Without this
change it is easy to confuse `ID` with a concept relating to peer IDs (and thus
implying this function somehow computes a hash pre-image to get the
corrresponding public key.
2019-08-14 14:27:04 -07:00
Steven Allen
c2a62a74af feat(peer): implement AddrInfosFromP2pAddrs and SplitAddr
* SplitAddr is a simpler way to split an address into a multiaddr and an ID.
* AddrInfosFromP2pAddrs converts a set of multiaddrs into a set of AddrInfos.
2019-05-31 12:25:57 -07:00
Steven Allen
ecce2522bf fix: handle empty addrs case 2019-05-30 22:25:37 -07:00
Steven Allen
5ea5a0797b chore: cleanup address parsing
* Use SplitLast to avoid allocating too much.
* Avoid converting to/from strings when working with multiaddrs.
2019-05-30 21:57:09 -07:00
Raúl Kripalani
79bf30a5a4 fix duplicated import. 2019-05-23 16:14:50 +01:00
Raúl Kripalani
07fbce0b46
absorb {crypto,peer} test utils. (#8)
Avoids circular module dependency.
2019-05-23 16:07:58 +01:00
Raúl Kripalani
6e566d10f4
Absorb go-libp2p abstractions and core types into this module (#1) 2019-05-22 18:31:11 +01:00