mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-01 06:17:56 +08:00
* fix(autotls): renewal and AutoTLS.ShortAddrs
updates to p2p-forge/client with fix from
https://github.com/ipshipyard/p2p-forge/pull/42
we also add AutoTLS.ShortAddrs flag and enable it by default
to benefit from shorter addrs discusses in
https://github.com/ipshipyard/p2p-forge/pull/40
* test: fix flaky NewRandPort
reducing chance of bind: address already in use
(cherry picked from commit 256a739e3b)
45 lines
898 B
Go
45 lines
898 B
Go
package harness
|
|
|
|
import (
|
|
"fmt"
|
|
"math/rand"
|
|
"net"
|
|
"testing"
|
|
|
|
"github.com/ipfs/kubo/config"
|
|
)
|
|
|
|
type Peering struct {
|
|
From int
|
|
To int
|
|
}
|
|
|
|
func NewRandPort() int {
|
|
if a, err := net.ResolveTCPAddr("tcp", "localhost:0"); err == nil {
|
|
var l *net.TCPListener
|
|
if l, err = net.ListenTCP("tcp", a); err == nil {
|
|
defer l.Close()
|
|
return l.Addr().(*net.TCPAddr).Port
|
|
}
|
|
}
|
|
n := rand.Int()
|
|
return 3000 + (n % 1000)
|
|
}
|
|
|
|
func CreatePeerNodes(t *testing.T, n int, peerings []Peering) (*Harness, Nodes) {
|
|
h := NewT(t)
|
|
nodes := h.NewNodes(n).Init()
|
|
nodes.ForEachPar(func(node *Node) {
|
|
node.UpdateConfig(func(cfg *config.Config) {
|
|
cfg.Routing.Type = config.NewOptionalString("none")
|
|
cfg.Addresses.Swarm = []string{fmt.Sprintf("/ip4/127.0.0.1/tcp/%d", NewRandPort())}
|
|
})
|
|
})
|
|
|
|
for _, peering := range peerings {
|
|
nodes[peering.From].PeerWith(nodes[peering.To])
|
|
}
|
|
|
|
return h, nodes
|
|
}
|