Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type IpfsNode struct {

// the name system, resolves paths to hashes
// Namesys *namesys.Namesys

}

// NewIpfsNode constructs a new IpfsNode based on the given config.
Expand All @@ -77,8 +78,8 @@ func NewIpfsNode(cfg *config.Config, online bool) (*IpfsNode, error) {
var (
net *swarm.Swarm
// TODO: refactor so we can use IpfsRouting interface instead of being DHT-specific
route* dht.IpfsDHT
swap *bitswap.BitSwap
route *dht.IpfsDHT
swap *bitswap.BitSwap
)

if online {
Expand Down Expand Up @@ -134,7 +135,7 @@ func initIdentity(cfg *config.Config) (*peer.Peer, error) {
return nil, err
}

addresses = []*ma.Multiaddr{ maddr }
addresses = []*ma.Multiaddr{maddr}
}

skb, err := base64.StdEncoding.DecodeString(cfg.Identity.PrivKey)
Expand Down
65 changes: 65 additions & 0 deletions daemon/daemon_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package daemon

import (
"encoding/base64"
"testing"

config "github.com/jbenet/go-ipfs/config"
core "github.com/jbenet/go-ipfs/core"
ci "github.com/jbenet/go-ipfs/crypto"
identify "github.com/jbenet/go-ipfs/identify"
)

func TestDaemonListener(t *testing.T) {

priv, pub, err := ci.GenerateKeyPair(ci.RSA, 512)
if err != nil {
t.Fatal(err)
}
prbytes, err := priv.Bytes()
if err != nil {
t.Fatal(err)
}

ident, _ := identify.IDFromPubKey(pub)
privKey := base64.StdEncoding.EncodeToString(prbytes)
pID := ident.Pretty()

id := &config.Identity{
PeerID: pID,
Address: "/ip4/127.0.0.1/tcp/8000",
PrivKey: privKey,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont know if it really matters for the test here, but PeerID can be set to the hash of the public key. I beleive there is a method somewhere (in the crypto package) called IDfromPubKey or something.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added*

}

nodeConfigs := []*config.Config{
&config.Config{
Identity: id,
Datastore: config.Datastore{
Type: "memory",
},
},

&config.Config{
Identity: id,
Datastore: config.Datastore{
Type: "leveldb",
Path: ".testdb",
},
},
}

for _, c := range nodeConfigs {

node, _ := core.NewIpfsNode(c, false)
dl, initErr := NewDaemonListener(node, "localhost:1327")
if initErr != nil {
t.Fatal(initErr)
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sure it starts up, then make sure it tears down. Good.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx

closeErr := dl.Close()
if closeErr != nil {
t.Fatal(closeErr)
}

}

}
11 changes: 8 additions & 3 deletions routing/dht/providers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ func TestProviderManager(t *testing.T) {
p := NewProviderManager(mid)
a := u.Key("test")
p.AddProvider(a, &peer.Peer{})
resp := p.GetProviders(a)
if len(resp) != 1 {
t.Fatal("Could not retrieve provider.")
remotePeers := p.GetProviders(a)
localPeers := p.GetLocal()
if len(remotePeers) != 1 {
t.Fatal("Could not retrieve remote provider.")
}
if len(localPeers) != 1 {
t.Fatal("Could not retrieve local provider.")
}

p.Halt()
}