MCPcopy
hub / github.com/ipfs/kubo / MakeAPISwarm

Method MakeAPISwarm

core/coreapi/test/api_test.go:34–124  ·  view source on GitHub ↗
(t *testing.T, ctx context.Context, fullIdentity bool, online bool, n int)

Source from the content-addressed store, hash-verified

32type NodeProvider struct{}
33
34func (NodeProvider) MakeAPISwarm(t *testing.T, ctx context.Context, fullIdentity bool, online bool, n int) ([]coreiface.CoreAPI, error) {
35 mn := mocknet.New()
36
37 nodes := make([]*core.IpfsNode, n)
38 apis := make([]coreiface.CoreAPI, n)
39
40 for i := range n {
41 var ident config.Identity
42 if fullIdentity {
43 sk, pk, err := crypto.GenerateKeyPair(crypto.RSA, 2048)
44 if err != nil {
45 return nil, err
46 }
47
48 id, err := peer.IDFromPublicKey(pk)
49 if err != nil {
50 return nil, err
51 }
52
53 kbytes, err := crypto.MarshalPrivateKey(sk)
54 if err != nil {
55 return nil, err
56 }
57
58 ident = config.Identity{
59 PeerID: id.String(),
60 PrivKey: base64.StdEncoding.EncodeToString(kbytes),
61 }
62 } else {
63 ident = config.Identity{
64 PeerID: testPeerID,
65 }
66 }
67
68 c := config.Config{}
69 c.Addresses.Swarm = []string{fmt.Sprintf("/ip4/18.0.%d.1/tcp/4001", i)}
70 c.Identity = ident
71 c.Experimental.FilestoreEnabled = true
72 c.AutoTLS.Enabled = config.False // disable so no /ws listener is added
73 // For provider tests, avoid that content gets
74 // auto-provided without calling "provide" (unless pinned).
75 c.Provide.Strategy = config.NewOptionalString("roots")
76
77 ds := syncds.MutexWrap(datastore.NewMapDatastore())
78 r := &repo.Mock{
79 C: c,
80 D: ds,
81 K: keystore.NewMemKeystore(),
82 F: filestore.NewFileManager(ds, filepath.Dir(os.TempDir())),
83 }
84
85 node, err := core.NewNode(ctx, &core.BuildCfg{
86 Routing: libp2p.DHTServerOption,
87 Repo: r,
88 Host: mock.MockHostOption(mn),
89 Online: online,
90 ExtraOpts: map[string]bool{
91 "pubsub": true,

Callers

nothing calls this directly

Calls 5

NewOptionalStringFunction · 0.92
NewNodeFunction · 0.92
NewCoreAPIFunction · 0.92
StringMethod · 0.45
BootstrapMethod · 0.45

Tested by

no test coverage detected