diff --git a/core/core.go b/core/core.go index 50fdacb9b..92f2c3d8a 100644 --- a/core/core.go +++ b/core/core.go @@ -1,62 +1,62 @@ package core import ( - config "github.com/jbenet/go-ipfs/config" - ds "github.com/jbenet/datastore.go" - "fmt" - peer "github.com/jbenet/go-ipfs/peer" + "fmt" + ds "github.com/jbenet/datastore.go" + config "github.com/jbenet/go-ipfs/config" + peer "github.com/jbenet/go-ipfs/peer" ) // IPFS Core module. It represents an IPFS instance. type IpfsNode struct { - // the node's configuration - Config *config.Config + // the node's configuration + Config *config.Config - // the local node's identity - Identity *peer.Peer + // the local node's identity + Identity *peer.Peer - // the book of other nodes (a map of Peer instances) - PeerBook *peer.PeerBook + // the book of other nodes (a map of Peer instances) + PeerBook *peer.PeerBook - // the local datastore - Datastore ds.Datastore + // the local datastore + Datastore ds.Datastore - // the network message stream - // Network *netmux.Netux + // the network message stream + // Network *netmux.Netux - // the routing system. recommend ipfs-dht - // Routing *routing.Routing + // the routing system. recommend ipfs-dht + // Routing *routing.Routing - // the block exchange + strategy (bitswap) - // BitSwap *bitswap.BitSwap + // the block exchange + strategy (bitswap) + // BitSwap *bitswap.BitSwap - // the block service, get/add blocks. - // Blocks *blocks.BlockService + // the block service, get/add blocks. + // Blocks *blocks.BlockService - // the path resolution system - // Resolver *resolver.PathResolver + // the path resolution system + // Resolver *resolver.PathResolver - // the name system, resolves paths to hashes - // Namesys *namesys.Namesys + // the name system, resolves paths to hashes + // Namesys *namesys.Namesys } func NewIpfsNode(cfg *config.Config) (*IpfsNode, error) { - if cfg == nil { - return nil, fmt.Errorf("configuration required.") - } + if cfg == nil { + return nil, fmt.Errorf("configuration required.") + } - d, err := makeDatastore(cfg.Datastore) - if err != nil { - return nil, err - } + d, err := makeDatastore(cfg.Datastore) + if err != nil { + return nil, err + } - n := &IpfsNode{ - Config: cfg, - PeerBook: &peer.PeerBook{}, - Datastore: d, - } + n := &IpfsNode{ + Config: cfg, + PeerBook: &peer.PeerBook{}, + Datastore: d, + } - return n, nil + return n, nil } diff --git a/core/core_test.go b/core/core_test.go index cc3e8e05e..3ab5fadc1 100644 --- a/core/core_test.go +++ b/core/core_test.go @@ -1,35 +1,35 @@ package core import ( - "testing" - config "github.com/jbenet/go-ipfs/config" + config "github.com/jbenet/go-ipfs/config" + "testing" ) func TestDatastores(t *testing.T) { - good := []*config.Config { - &config.Config{ Datastore: &config.Datastore{Type: "memory"} }, - &config.Config{ Datastore: &config.Datastore{Type: "leveldb", Path: ".testdb"} }, - } + good := []*config.Config{ + &config.Config{Datastore: &config.Datastore{Type: "memory"}}, + &config.Config{Datastore: &config.Datastore{Type: "leveldb", Path: ".testdb"}}, + } - bad := []*config.Config { - &config.Config{ Datastore: &config.Datastore{} }, - &config.Config{ Datastore: &config.Datastore{Type: "badtype"} }, - &config.Config{ }, - nil, - } + bad := []*config.Config{ + &config.Config{Datastore: &config.Datastore{}}, + &config.Config{Datastore: &config.Datastore{Type: "badtype"}}, + &config.Config{}, + nil, + } - for i, c := range(good) { - n, err := NewIpfsNode(c) - if n == nil || err != nil { - t.Error("Should have constructed.", i, err) - } - } + for i, c := range good { + n, err := NewIpfsNode(c) + if n == nil || err != nil { + t.Error("Should have constructed.", i, err) + } + } - for i, c := range(bad) { - n, err := NewIpfsNode(c) - if n != nil || err == nil { - t.Error("Should have failed to construct.", i) - } - } + for i, c := range bad { + n, err := NewIpfsNode(c) + if n != nil || err == nil { + t.Error("Should have failed to construct.", i) + } + } } diff --git a/core/datastore.go b/core/datastore.go index 8fa6be671..10efc6582 100644 --- a/core/datastore.go +++ b/core/datastore.go @@ -1,29 +1,31 @@ package core import ( - config "github.com/jbenet/go-ipfs/config" - ds "github.com/jbenet/datastore.go" - "fmt" - lds "github.com/jbenet/datastore.go/leveldb" + "fmt" + ds "github.com/jbenet/datastore.go" + lds "github.com/jbenet/datastore.go/leveldb" + config "github.com/jbenet/go-ipfs/config" ) func makeDatastore(cfg *config.Datastore) (ds.Datastore, error) { - if cfg == nil || len(cfg.Type) == 0 { - return nil, fmt.Errorf("config datastore.type required") - } + if cfg == nil || len(cfg.Type) == 0 { + return nil, fmt.Errorf("config datastore.type required") + } - switch cfg.Type { - case "leveldb": return makeLevelDBDatastore(cfg) - case "memory": return ds.NewMapDatastore(), nil - } + switch cfg.Type { + case "leveldb": + return makeLevelDBDatastore(cfg) + case "memory": + return ds.NewMapDatastore(), nil + } - return nil, fmt.Errorf("Unknown datastore type: %s", cfg.Type) + return nil, fmt.Errorf("Unknown datastore type: %s", cfg.Type) } func makeLevelDBDatastore(cfg *config.Datastore) (ds.Datastore, error) { - if len(cfg.Path) == 0 { - return nil, fmt.Errorf("config datastore.path required for leveldb") - } + if len(cfg.Path) == 0 { + return nil, fmt.Errorf("config datastore.path required for leveldb") + } - return lds.NewDatastore(cfg.Path, nil) + return lds.NewDatastore(cfg.Path, nil) }