diff --git a/bzz/protocol.go b/bzz/protocol.go index 6a7afdc7d1..72f163d750 100644 --- a/bzz/protocol.go +++ b/bzz/protocol.go @@ -204,25 +204,25 @@ main entrypoint, wrappers starting a server running the bzz protocol use this constructor to attach the protocol ("class") to server caps the Dev p2p layer then runs the protocol instance on each peer */ -func BzzProtocol(netStore *NetStore) p2p.Protocol { +func BzzProtocol(netStore *NetStore) (p2p.Protocol, error) { + + db, err := NewLDBDatabase(path.Join(netStore.path, "requests")) + if err != nil { + return p2p.Protocol{}, err + } return p2p.Protocol{ Name: "bzz", Version: Version, Length: ProtocolLength, Run: func(p *p2p.Peer, rw p2p.MsgReadWriter) error { - return runBzzProtocol(netStore, p, rw) + return runBzzProtocol(db, netStore, p, rw) }, - } + }, nil } // the main loop that handles incoming messages // note RemovePeer in the post-disconnect hook -func runBzzProtocol(netStore *NetStore, p *p2p.Peer, rw p2p.MsgReadWriter) (err error) { - - db, err := NewLDBDatabase(path.Join(netStore.path, "requests")) - if err != nil { - return - } +func runBzzProtocol(db *LDBDatabase, netStore *NetStore, p *p2p.Peer, rw p2p.MsgReadWriter) (err error) { self := &bzzProtocol{ netStore: netStore, diff --git a/eth/backend.go b/eth/backend.go index d699a41961..b914162824 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -293,7 +293,7 @@ func New(config *Config) (*Ethereum, error) { protocols := []p2p.Protocol{eth.protocolManager.SubProtocol} if config.Bzz { - eth.netStore, err = bzz.NewNetStore(path.Join(config.DataDir, "bzz"), path.Join(config.DataDir, "bzzpeers.json")) + eth.netStore, err = bzz.NewNetStore(filepath.Join(config.DataDir, "bzz"), filepath.Join(config.DataDir, "bzzpeers.json")) if err != nil { glog.V(logger.Warn).Infof("BZZ: error creating net store: %v. Protocol skipped", err) } else { @@ -303,7 +303,10 @@ func New(config *Config) (*Ethereum, error) { Chunker: chunker, ChunkStore: eth.netStore, } - protocols = append(protocols, bzz.BzzProtocol(eth.netStore)) + bzzProto, err := bzz.BzzProtocol(eth.netStore) + if err != nil { + protocols = append(protocols, bzzProto) + } } }