mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-26 23:53:19 +08:00
integrate circuit-relay transport
- enabled by default, so that we can dial/receive dials - /p2p-circuit/QmId address is not announced; filtered at host with AddrsFactory - use case is manual swarm connect with relay address License: MIT Signed-off-by: vyzo <vyzo@hackzen.org>
This commit is contained in:
35
core/core.go
35
core/core.go
@ -56,6 +56,7 @@ import (
|
||||
logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
|
||||
b58 "gx/ipfs/QmT8rehPR3F6bmwL6zjUN8XpiDBFFpMP2myPdC6ApsWfJf/go-base58"
|
||||
cid "gx/ipfs/QmTprEaAA2A9bst5XH7exuyi5KzNMK3SEDNN8rBDnKWcUS/go-cid"
|
||||
circuit "gx/ipfs/QmVEPsD9h95ToAC7NJpYopFcXyjVJm35xV4tw43J5JdCnL/go-libp2p-circuit"
|
||||
ds "gx/ipfs/QmVSase1JP7cq9QkPT46oNwdp9pT6kBkG3oqS14y3QcZjG/go-datastore"
|
||||
metrics "gx/ipfs/QmVjRAPfRtResCMCE4eBqr4Beoa6A89P1YweG9wUS6RqUL/go-libp2p-metrics"
|
||||
ma "gx/ipfs/QmXY77cVe7rVRQXZZQRioukUM7aRW3BTcAgJe12MCtb3Ji/go-multiaddr"
|
||||
@ -221,9 +222,12 @@ func (n *IpfsNode) startOnlineServices(ctx context.Context, routingOption Routin
|
||||
hostopts := &ConstructPeerHostOpts{
|
||||
AddrsFactory: addrsFactory,
|
||||
DisableNatPortMap: cfg.Swarm.DisableNatPortMap,
|
||||
DisableRelay: cfg.Swarm.DisableRelay,
|
||||
EnableRelayHop: cfg.Swarm.EnableRelayHop,
|
||||
}
|
||||
peerhost, err := hostOption(ctx, n.Identity, n.Peerstore, n.Reporter,
|
||||
addrfilter, tpt, protec, hostopts)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -783,8 +787,10 @@ func listenAddresses(cfg *config.Config) ([]ma.Multiaddr, error) {
|
||||
}
|
||||
|
||||
type ConstructPeerHostOpts struct {
|
||||
DisableNatPortMap bool
|
||||
AddrsFactory p2pbhost.AddrsFactory
|
||||
DisableNatPortMap bool
|
||||
DisableRelay bool
|
||||
EnableRelayHop bool
|
||||
}
|
||||
|
||||
type HostOption func(ctx context.Context, id peer.ID, ps pstore.Peerstore, bwr metrics.Reporter, fs []*net.IPNet, tpt smux.Transport, protc ipnet.Protector, opts *ConstructPeerHostOpts) (p2phost.Host, error)
|
||||
@ -814,8 +820,35 @@ func constructPeerHost(ctx context.Context, id peer.ID, ps pstore.Peerstore, bwr
|
||||
hostOpts = append(hostOpts, opts.AddrsFactory)
|
||||
}
|
||||
|
||||
if !opts.DisableRelay {
|
||||
filterRelayAddr := func(addrs []ma.Multiaddr) []ma.Multiaddr {
|
||||
var raddrs []ma.Multiaddr
|
||||
for _, addr := range addrs {
|
||||
_, err := addr.ValueForProtocol(circuit.P_CIRCUIT)
|
||||
if err == nil {
|
||||
continue
|
||||
}
|
||||
raddrs = append(raddrs, addr)
|
||||
}
|
||||
return raddrs
|
||||
}
|
||||
hostOpts = append(hostOpts, p2pbhost.AddrsFactory(filterRelayAddr))
|
||||
}
|
||||
|
||||
host := p2pbhost.New(network, hostOpts...)
|
||||
|
||||
if !opts.DisableRelay {
|
||||
var relayOpts []circuit.RelayOpt
|
||||
if opts.EnableRelayHop {
|
||||
relayOpts = append(relayOpts, circuit.OptHop)
|
||||
}
|
||||
|
||||
err := circuit.AddRelayTransport(ctx, host, relayOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return host, nil
|
||||
}
|
||||
|
||||
|
@ -451,6 +451,12 @@
|
||||
"hash": "QmQBB2dQLmQHJgs2gqZ3iqL2XiuCtUCvXzWt5kMXDf5Zcr",
|
||||
"name": "go-maddr-filter",
|
||||
"version": "1.1.4"
|
||||
},
|
||||
{
|
||||
"author": "vyzo",
|
||||
"hash": "QmVEPsD9h95ToAC7NJpYopFcXyjVJm35xV4tw43J5JdCnL",
|
||||
"name": "go-libp2p-circuit",
|
||||
"version": "1.1.1"
|
||||
}
|
||||
],
|
||||
"gxVersion": "0.10.0",
|
||||
@ -459,4 +465,3 @@
|
||||
"name": "go-ipfs",
|
||||
"version": "0.4.11-dev"
|
||||
}
|
||||
|
||||
|
@ -4,4 +4,6 @@ type SwarmConfig struct {
|
||||
AddrFilters []string
|
||||
DisableBandwidthMetrics bool
|
||||
DisableNatPortMap bool
|
||||
DisableRelay bool
|
||||
EnableRelayHop bool
|
||||
}
|
||||
|
Reference in New Issue
Block a user