fix path->filepath; open requestDB only once in bzzProtocol

This commit is contained in:
zelig 2015-05-16 15:20:06 +02:00
parent c9a598ed4c
commit 89df3a4648
2 changed files with 14 additions and 11 deletions

View file

@ -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,

View file

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