Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Daemon and DHT Tests #79

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 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
24 changes: 21 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 Expand Up @@ -174,3 +175,20 @@ func (n *IpfsNode) PinDagNode(nd *merkledag.Node) error {
u.POut("Pinning node. Currently No-Op\n")
return nil
}

func (n *IpfsNode) Close() (*IpfsNode, error) {
//n.Swarm.Close()

return &IpfsNode{
Config: nil,
PeerMap: nil,
Datastore: nil,
Copy link
Member

Choose a reason for hiding this comment

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

The Close method should shut down each of the individual subsystems in core. im not quite sure whats going on here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah k, need to convert c++ mentality to go

Blocks: nil,
DAG: nil,
Resolver: nil,
BitSwap: nil,
Identity: nil,
Routing: nil,
}, nil

}
2 changes: 2 additions & 0 deletions core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ func TestInitialization(t *testing.T) {
if n == nil || err != nil {
t.Error("Should have constructed.", i, err)
}
n.Close()
}

for i, c := range bad {
n, err := NewIpfsNode(c, false)
if n != nil || err == nil {
t.Error("Should have failed to construct.", i)
}
n.Close()
}
}
63 changes: 63 additions & 0 deletions daemon/daemon_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
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"
)

func TestDaemonListener(t *testing.T) {

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

privKey := base64.StdEncoding.EncodeToString(prbytes)

id := &config.Identity{
PeerID: "QmNgdzLieYi8tgfo2WfTUzNVH5hQK9oAYGVf6dxN12NrHt",
Address: "/ip4/127.0.0.1/tcp/8000",
PrivKey: privKey,
Copy link
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
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
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
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)
}
node.Close()

}

}
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()
}