Skip to content

Commit

Permalink
Merge branch 'master' of github.com:llSourcell/go-ipfs
Browse files Browse the repository at this point in the history
  • Loading branch information
whyrusleeping committed Sep 18, 2014
2 parents d326fc6 + fafdc17 commit 609a71b
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 6 deletions.
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,
}

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

0 comments on commit 609a71b

Please sign in to comment.