mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 10:27:46 +08:00
assign public IP addresses for tests that need them
This commit is contained in:
parent
8a002250dc
commit
bb08f7fe56
@ -65,7 +65,7 @@ func (NodeProvider) MakeAPISwarm(ctx context.Context, fullIdentity bool, n int)
|
||||
}
|
||||
|
||||
c := config.Config{}
|
||||
c.Addresses.Swarm = []string{fmt.Sprintf("/ip4/127.0.%d.1/tcp/4001", i)}
|
||||
c.Addresses.Swarm = []string{fmt.Sprintf("/ip4/18.0.%d.1/tcp/4001", i)}
|
||||
c.Identity = ident
|
||||
c.Experimental.FilestoreEnabled = true
|
||||
|
||||
|
||||
@ -2,6 +2,8 @@ package coremock
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
||||
libp2p2 "github.com/ipfs/go-ipfs/core/node/libp2p"
|
||||
|
||||
@ -75,3 +77,24 @@ func MockCmdsCtx() (commands.Context, error) {
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func MockPublicNode(ctx context.Context, mn mocknet.Mocknet) (*core.IpfsNode, error) {
|
||||
ds := syncds.MutexWrap(datastore.NewMapDatastore())
|
||||
cfg, err := config.Init(ioutil.Discard, 2048)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
count := len(mn.Peers())
|
||||
cfg.Addresses.Swarm = []string{
|
||||
fmt.Sprintf("/ip4/18.0.%d.%d/tcp/4001", count>>16, count&0xFF),
|
||||
}
|
||||
cfg.Datastore = config.Datastore{}
|
||||
return core.NewNode(ctx, &core.BuildCfg{
|
||||
Online: true,
|
||||
Repo: &repo.Mock{
|
||||
C: *cfg,
|
||||
D: ds,
|
||||
},
|
||||
Host: MockHostOption(mn),
|
||||
})
|
||||
}
|
||||
|
||||
@ -29,10 +29,7 @@ func TestRepublish(t *testing.T) {
|
||||
|
||||
var nodes []*core.IpfsNode
|
||||
for i := 0; i < 10; i++ {
|
||||
nd, err := core.NewNode(ctx, &core.BuildCfg{
|
||||
Online: true,
|
||||
Host: mock.MockHostOption(mn),
|
||||
})
|
||||
nd, err := mock.MockPublicNode(ctx, mn)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@ -9,7 +9,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
core "github.com/ipfs/go-ipfs/core"
|
||||
bootstrap2 "github.com/ipfs/go-ipfs/core/bootstrap"
|
||||
"github.com/ipfs/go-ipfs/core/coreapi"
|
||||
mock "github.com/ipfs/go-ipfs/core/mock"
|
||||
@ -76,28 +75,19 @@ func RunThreeLeggedCat(data []byte, conf testutil.LatencyConfig) error {
|
||||
Bandwidth: math.MaxInt32,
|
||||
})
|
||||
|
||||
bootstrap, err := core.NewNode(ctx, &core.BuildCfg{
|
||||
Online: true,
|
||||
Host: mock.MockHostOption(mn),
|
||||
})
|
||||
bootstrap, err := mock.MockPublicNode(ctx, mn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer bootstrap.Close()
|
||||
|
||||
adder, err := core.NewNode(ctx, &core.BuildCfg{
|
||||
Online: true,
|
||||
Host: mock.MockHostOption(mn),
|
||||
})
|
||||
adder, err := mock.MockPublicNode(ctx, mn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer adder.Close()
|
||||
|
||||
catter, err := core.NewNode(ctx, &core.BuildCfg{
|
||||
Online: true,
|
||||
Host: mock.MockHostOption(mn),
|
||||
})
|
||||
catter, err := mock.MockPublicNode(ctx, mn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user