Skip to content

Commit

Permalink
core: address factory composition for constructPeerHost
Browse files Browse the repository at this point in the history
- Adds AddrsFactory to ConstructPeerHostOpts
- Composes the AddrsFactory option with the relay filter

License: MIT
Signed-off-by: vyzo <vyzo@hackzen.org>
  • Loading branch information
vyzo committed Aug 1, 2017
1 parent 5865a00 commit 74ed977
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,7 @@ func constructPeerHost(ctx context.Context, id peer.ID, ps pstore.Peerstore, bwr
hostOpts = append(hostOpts, opts.AddrsFactory)
}

addrsFactory := opts.AddrsFactory
if !opts.DisableRelay {
filterRelayAddr := func(addrs []ma.Multiaddr) []ma.Multiaddr {
var raddrs []ma.Multiaddr
Expand All @@ -809,7 +810,16 @@ func constructPeerHost(ctx context.Context, id peer.ID, ps pstore.Peerstore, bwr
}
return raddrs
}
hostOpts = append(hostOpts, p2pbhost.AddrsFactory(filterRelayAddr))

if addrsFactory != nil {
addrsFactory = composeAddrsFactory(addrsFactory, filterRelayAddr)
} else {
addrsFactory = filterRelayAddr
}
}

if addrsFactory != nil {
hostOpts = append(hostOpts, addrsFactory)
}

host := p2pbhost.New(network, hostOpts...)
Expand All @@ -829,6 +839,12 @@ func constructPeerHost(ctx context.Context, id peer.ID, ps pstore.Peerstore, bwr
return host, nil
}

func composeAddrsFactory(f, g p2pbhost.AddrsFactory) p2pbhost.AddrsFactory {
return func(addrs []ma.Multiaddr) []ma.Multiaddr {
return f(g(addrs))
}
}

// startListening on the network addresses
func startListening(ctx context.Context, host p2phost.Host, cfg *config.Config) error {
listenAddrs, err := listenAddresses(cfg)
Expand Down

0 comments on commit 74ed977

Please sign in to comment.