Skip to content

Commit 1bfb703

Browse files
authored
New gossip_net backend using libp2p (#3988)
This is the revival of the tmp/cmr/net2 branch rebased onto develop. Some important user-facing changes: - No separate discovery/communication/etc ports. One port for all public daemon communications. - Automatic port forwarding with UPnP. If your local network supports UPnP, there should be no configuration required. - Local peer discovery. If your local network supports mDNS broadcast, coda daemons will automatically discover each other. This includes several daemons on the same machine- no more building peer lists! - New libp2p keypairs. These are managed the same as our key pairs with secret_file. Without configuration, key pairs are ephemeral and will disappear when the daemon restarts. (TODO: should we instead persist the keypair? does it matter for non-infrastructure?) Some important internal changes: - All daemon-daemon connections are now authenticated and confidential. - Connections are no longer transient and per-request. Individual requests get multiplexed as their own stream over the one connection between the peers. This is analogous to HTTP/2. Outgoing connections will appear to originate from the libp2p listening port, vs some transient port. Outstanding details: - Trust system needs to get augmented to track Peer.t instead of just an IP. Until then we can't implement ban_notify (#4093, #4096). - Libp2p has little per-connection structured reporting, some things we currently penalize trust for are not detected (eg opening a libp2p connection without also opening a coda RPC stream) (#4098). - New pubsub allows banning senders by peer ID. We currently don't do this but we should ban peerIDs that originated bad info and not just the IP of the whoever relayed it to us (#4096). - ~~Current pubsub validation flow goes a bit against the libp2p grain, and it's not clear to me that the current behavior will survive [this libp2p PR](libp2p/go-libp2p-kad-dht#388). There's an inline comment near the should_forward_message impl (#4097).~~ done - Connection limit enforcement (#4095) Other changes: - Rips out the last vestiges of old membership, which aren't in use. - The connection info in envelopes is much more accurate now. We shouldn't start trusting it just yet due to some future vagaries around relaying. - bump nixpkgs version Future improvements: - IPv6. There's a hardcoded IPv4 assumption in the helper around IP filtering. - Investigate libp2p autorelay. This should help nodes in restrictive networks achieve better connectivity, but has a host of problems. - Intelligent request routing. I believe we can use the "provider" feature to, at the very least, only send eg sync/bootstrap requests to nodes who believe themselves to be in sync. There are other options.
1 parent 39ef94a commit 1bfb703

File tree

10 files changed

+1539
-138
lines changed

10 files changed

+1539
-138
lines changed

build/DEBIAN/control

Lines changed: 0 additions & 9 deletions
This file was deleted.

default.nix

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
((import (builtins.fetchTarball {
2-
name = "nixpkgs-unstable-2019-03-18";
3-
url = https://github.com/nixos/nixpkgs/archive/0125544e2a0552590c87dca1583768b49ba911c0.tar.gz;
4-
sha256 = "04xvlqw3zbq91zkfa506b2k1ajmj7pqh3nvdh9maabw6m5jhm5rl";
2+
name = "nixpkgs-stable-2019-12-05";
3+
url = https://github.com/nixos/nixpkgs/archive/19.09.tar.gz;
4+
sha256 = "0mhqhq21y5vrr1f30qd2bvydv4bbbslvyzclhw0kdxmkgg3z4c92";
55
})) {}).buildGoModule rec {
66
name = "libp2p_helper-${version}";
77
version = "0.1";
88
src = ./src;
9-
modSha256 = "1spndcx0z50cmpfxfd0971nj9n0v77fghxl36hr1pvs6kv0ra5c3";
9+
modSha256 = "0wrqxik9z713w50w49ivy5c2vapk07fdmd0zsvk6kfkchkq1nsdy";
1010
}
1111

src/codanet.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
secio "github.com/libp2p/go-libp2p-secio"
2525
p2pconfig "github.com/libp2p/go-libp2p/config"
2626
mdns "github.com/libp2p/go-libp2p/p2p/discovery"
27+
filters "github.com/libp2p/go-maddr-filter"
2728
tcp "github.com/libp2p/go-tcp-transport"
2829
ws "github.com/libp2p/go-ws-transport"
2930
ma "github.com/multiformats/go-multiaddr"
@@ -38,9 +39,11 @@ type Helper struct {
3839
Ctx context.Context
3940
Pubsub *pubsub.PubSub
4041
Logger logging.EventLogger
42+
Filters *filters.Filters
4143
DiscoveredPeers chan peer.AddrInfo
4244
Rendezvous string
4345
Discovery *discovery.RoutingDiscovery
46+
Me peer.ID
4447
}
4548

4649
type customValidator struct {
@@ -62,6 +65,12 @@ func (cv customValidator) Select(key string, values [][]byte) (int, error) {
6265
// MakeHelper does all the initialization to run one host
6366
func MakeHelper(ctx context.Context, listenOn []ma.Multiaddr, externalAddr ma.Multiaddr, statedir string, pk crypto.PrivKey, networkID string) (*Helper, error) {
6467
logger := logging.Logger("codanet.Helper")
68+
69+
me, err := peer.IDFromPrivateKey(pk)
70+
if err != nil {
71+
return nil, err
72+
}
73+
6574
dso := dsb.DefaultOptions
6675

6776
ds, err := dsb.NewDatastore(path.Join(statedir, "libp2p-peerstore-v0"), &dso)
@@ -93,6 +102,8 @@ func MakeHelper(ctx context.Context, listenOn []ma.Multiaddr, externalAddr ma.Mu
93102
// gross hack to exfiltrate the DHT from the side effect of option evaluation
94103
kadch := make(chan *kad.IpfsDHT)
95104

105+
filters := filters.NewFilters()
106+
96107
// Make sure this doesn't get too out of sync with the defaults,
97108
// NewWithoutDefaults is considered unstable.
98109
host, err := p2p.NewWithoutDefaults(ctx,
@@ -108,6 +119,7 @@ func MakeHelper(ctx context.Context, listenOn []ma.Multiaddr, externalAddr ma.Mu
108119
as = append(as, externalAddr)
109120
return as
110121
}),
122+
p2p.Filters(filters),
111123
p2p.NATPortMap(),
112124
p2p.Routing(
113125
p2pconfig.RoutingC(func(host host.Host) (routing.PeerRouting, error) {
@@ -138,6 +150,8 @@ func MakeHelper(ctx context.Context, listenOn []ma.Multiaddr, externalAddr ma.Mu
138150
Logger: logger,
139151
DiscoveredPeers: nil,
140152
Rendezvous: rendezvousString,
153+
Filters: filters,
141154
Discovery: nil,
155+
Me: me,
142156
}, nil
143157
}

src/gen_keys/libp2p_priv_to_pub.go

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
11
package main
2+
23
import (
3-
crypto "github.com/libp2p/go-libp2p-crypto"
4-
b58 "github.com/mr-tron/base58/base58"
5-
"os"
6-
)
4+
crypto "github.com/libp2p/go-libp2p-crypto"
5+
b58 "github.com/mr-tron/base58/base58"
6+
"os"
7+
)
78

89
func main() {
9-
if len(os.Args) != 2 {
10-
println("usage: libp2p-priv-to-pub PRIVKEY_BASE58_STRING");
11-
}
12-
privk_enc := os.Args[1]
13-
privk_raw, err := b58.Decode(privk_enc)
14-
if err != nil { panic(err); }
10+
if len(os.Args) != 2 {
11+
println("usage: libp2p-priv-to-pub PRIVKEY_BASE58_STRING")
12+
}
13+
privk_enc := os.Args[1]
14+
privk_raw, err := b58.Decode(privk_enc)
15+
if err != nil {
16+
panic(err)
17+
}
1518

16-
priv, err := crypto.UnmarshalPrivateKey(privk_raw)
17-
if err != nil { panic(err); }
19+
priv, err := crypto.UnmarshalPrivateKey(privk_raw)
20+
if err != nil {
21+
panic(err)
22+
}
1823

19-
pub := priv.GetPublic()
24+
pub := priv.GetPublic()
2025

21-
pubk_raw, err := crypto.MarshalPublicKey(pub)
22-
if err != nil { panic(err); }
26+
pubk_raw, err := crypto.MarshalPublicKey(pub)
27+
if err != nil {
28+
panic(err)
29+
}
2330

24-
pubk_enc := b58.Encode(pubk_raw)
31+
pubk_enc := b58.Encode(pubk_raw)
2532

26-
println(pubk_enc)
33+
println(pubk_enc)
2734
}

src/generate_methodidx/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func main() {
9999
Command: "generate_methodidx",
100100
PackageName: "main",
101101
TypesAndValues: map[string][]string{
102-
"methodIdx": []string{"configure", "listen", "publish", "subscribe", "unsubscribe", "validationComplete", "generateKeypair", "openStream", "closeStream", "resetStream", "sendStreamMsg", "removeStreamHandler", "addStreamHandler", "listeningAddrs", "addPeer", "beginAdvertising"},
102+
"methodIdx": []string{"configure", "listen", "publish", "subscribe", "unsubscribe", "validationComplete", "generateKeypair", "openStream", "closeStream", "resetStream", "sendStreamMsg", "removeStreamHandler", "addStreamHandler", "listeningAddrs", "addPeer", "beginAdvertising", "findPeer", "listPeers", "banIP", "unbanIP"},
103103
},
104104
}
105105

src/go.mod

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,72 +4,59 @@ go 1.12
44

55
require (
66
cloud.google.com/go v0.43.0 // indirect
7-
github.com/Kubuxu/go-os-helper v0.0.1 // indirect
8-
github.com/btcsuite/btcd v0.0.0-20190629003639-c26ffa870fd8 // indirect
97
github.com/btcsuite/goleveldb v1.0.0 // indirect
108
github.com/campoy/jsonenums v0.0.0-20180221195324-eec6d38da64e
119
github.com/coreos/bbolt v1.3.3 // indirect
1210
github.com/coreos/etcd v3.3.13+incompatible // indirect
1311
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f // indirect
1412
github.com/davidlazar/go-crypto v0.0.0-20190522120613-62389b5e4ae0 // indirect
15-
github.com/dgraph-io/badger v1.6.0 // indirect
1613
github.com/go-errors/errors v1.0.1
1714
github.com/go-kit/kit v0.9.0 // indirect
18-
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6 // indirect
1915
github.com/golang/snappy v0.0.1 // indirect
2016
github.com/google/pprof v0.0.0-20190723021845-34ac40c74b70 // indirect
2117
github.com/grpc-ecosystem/grpc-gateway v1.9.5 // indirect
2218
github.com/hashicorp/go-multierror v1.0.0 // indirect
23-
github.com/hashicorp/golang-lru v0.5.3 // indirect
24-
github.com/ipfs/go-cid v0.0.3 // indirect
25-
github.com/ipfs/go-ds-badger v0.0.5
26-
github.com/ipfs/go-ds-leveldb v0.0.2 // indirect
19+
github.com/ipfs/go-ds-badger v0.0.7
2720
github.com/ipfs/go-ipfs-delay v0.0.1 // indirect
2821
github.com/ipfs/go-log v0.0.1
2922
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
30-
github.com/kisielk/errcheck v1.2.0 // indirect
3123
github.com/kkdai/bstream v1.0.0 // indirect
3224
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
3325
github.com/kr/pty v1.1.8 // indirect
26+
github.com/libp2p/go-buffer-pool v0.0.2
3427
github.com/libp2p/go-conn-security v0.1.0 // indirect
35-
github.com/libp2p/go-eventbus v0.0.3 // indirect
36-
github.com/libp2p/go-libp2p v0.2.1
37-
github.com/libp2p/go-libp2p-circuit v0.1.1 // indirect
38-
github.com/libp2p/go-libp2p-core v0.2.0
28+
github.com/libp2p/go-libp2p v0.4.2
29+
github.com/libp2p/go-libp2p-core v0.2.4
3930
github.com/libp2p/go-libp2p-crypto v0.1.0
40-
github.com/libp2p/go-libp2p-discovery v0.1.0
31+
github.com/libp2p/go-libp2p-discovery v0.2.0
4132
github.com/libp2p/go-libp2p-host v0.1.0
4233
github.com/libp2p/go-libp2p-interface-connmgr v0.1.0 // indirect
4334
github.com/libp2p/go-libp2p-interface-pnet v0.1.0 // indirect
44-
github.com/libp2p/go-libp2p-kad-dht v0.1.1
35+
github.com/libp2p/go-libp2p-kad-dht v0.3.0
4536
github.com/libp2p/go-libp2p-metrics v0.1.0 // indirect
4637
github.com/libp2p/go-libp2p-net v0.1.0
4738
github.com/libp2p/go-libp2p-peer v0.2.0
48-
github.com/libp2p/go-libp2p-peerstore v0.1.3
39+
github.com/libp2p/go-libp2p-peerstore v0.1.4
4940
github.com/libp2p/go-libp2p-pnet v0.1.0
5041
github.com/libp2p/go-libp2p-protocol v0.1.0
51-
github.com/libp2p/go-libp2p-pubsub v0.1.0
42+
github.com/libp2p/go-libp2p-pubsub v0.2.3
5243
github.com/libp2p/go-libp2p-record v0.1.1
5344
github.com/libp2p/go-libp2p-routing v0.1.0
54-
github.com/libp2p/go-libp2p-secio v0.1.1
55-
github.com/libp2p/go-libp2p-testing v0.1.0 // indirect
45+
github.com/libp2p/go-libp2p-secio v0.2.1
5646
github.com/libp2p/go-libp2p-transport v0.1.0 // indirect
47+
github.com/libp2p/go-maddr-filter v0.0.5
5748
github.com/libp2p/go-mplex v0.1.0
5849
github.com/libp2p/go-stream-muxer v0.1.0
59-
github.com/libp2p/go-tcp-transport v0.1.0
50+
github.com/libp2p/go-tcp-transport v0.1.1
6051
github.com/libp2p/go-testutil v0.1.0 // indirect
61-
github.com/libp2p/go-ws-transport v0.1.0
52+
github.com/libp2p/go-ws-transport v0.1.2
6253
github.com/magiconair/properties v1.8.1 // indirect
6354
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e // indirect
6455
github.com/mattn/go-colorable v0.1.2 // indirect
6556
github.com/miekg/dns v1.1.15 // indirect
66-
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
67-
github.com/modern-go/reflect2 v1.0.1 // indirect
6857
github.com/mr-tron/base58 v1.1.2
69-
github.com/multiformats/go-multiaddr v0.0.4
70-
github.com/multiformats/go-multiaddr-dns v0.0.3 // indirect
58+
github.com/multiformats/go-multiaddr v0.1.1
7159
github.com/multiformats/go-multicodec v0.1.6 // indirect
72-
github.com/multiformats/go-multihash v0.0.6 // indirect
7360
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
7461
github.com/opentracing/opentracing-go v1.1.0 // indirect
7562
github.com/pelletier/go-toml v1.4.0 // indirect
@@ -89,13 +76,12 @@ require (
8976
github.com/whyrusleeping/go-smux-yamux v2.0.9+incompatible // indirect
9077
github.com/whyrusleeping/yamux v1.2.0 // indirect
9178
go.etcd.io/bbolt v1.3.3 // indirect
92-
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4
79+
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550
9380
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56 // indirect
9481
golang.org/x/image v0.0.0-20190802002840-cff245a6509b // indirect
9582
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028 // indirect
9683
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 // indirect
9784
golang.org/x/tools v0.0.0-20190802220118-1d1727260058 // indirect
98-
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 // indirect
9985
google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64 // indirect
10086
google.golang.org/grpc v1.22.1 // indirect
10187
gopkg.in/src-d/go-cli.v0 v0.0.0-20190422143124-3a646154da79 // indirect

0 commit comments

Comments
 (0)