mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 13:16:42 +00:00
fix path->filepath; open requestDB only once in bzzProtocol
This commit is contained in:
parent
c9a598ed4c
commit
89df3a4648
2 changed files with 14 additions and 11 deletions
|
|
@ -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
|
use this constructor to attach the protocol ("class") to server caps
|
||||||
the Dev p2p layer then runs the protocol instance on each peer
|
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{
|
return p2p.Protocol{
|
||||||
Name: "bzz",
|
Name: "bzz",
|
||||||
Version: Version,
|
Version: Version,
|
||||||
Length: ProtocolLength,
|
Length: ProtocolLength,
|
||||||
Run: func(p *p2p.Peer, rw p2p.MsgReadWriter) error {
|
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
|
// the main loop that handles incoming messages
|
||||||
// note RemovePeer in the post-disconnect hook
|
// note RemovePeer in the post-disconnect hook
|
||||||
func runBzzProtocol(netStore *NetStore, p *p2p.Peer, rw p2p.MsgReadWriter) (err error) {
|
func runBzzProtocol(db *LDBDatabase, netStore *NetStore, p *p2p.Peer, rw p2p.MsgReadWriter) (err error) {
|
||||||
|
|
||||||
db, err := NewLDBDatabase(path.Join(netStore.path, "requests"))
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
self := &bzzProtocol{
|
self := &bzzProtocol{
|
||||||
netStore: netStore,
|
netStore: netStore,
|
||||||
|
|
|
||||||
|
|
@ -293,7 +293,7 @@ func New(config *Config) (*Ethereum, error) {
|
||||||
protocols := []p2p.Protocol{eth.protocolManager.SubProtocol}
|
protocols := []p2p.Protocol{eth.protocolManager.SubProtocol}
|
||||||
|
|
||||||
if config.Bzz {
|
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 {
|
if err != nil {
|
||||||
glog.V(logger.Warn).Infof("BZZ: error creating net store: %v. Protocol skipped", err)
|
glog.V(logger.Warn).Infof("BZZ: error creating net store: %v. Protocol skipped", err)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -303,7 +303,10 @@ func New(config *Config) (*Ethereum, error) {
|
||||||
Chunker: chunker,
|
Chunker: chunker,
|
||||||
ChunkStore: eth.netStore,
|
ChunkStore: eth.netStore,
|
||||||
}
|
}
|
||||||
protocols = append(protocols, bzz.BzzProtocol(eth.netStore))
|
bzzProto, err := bzz.BzzProtocol(eth.netStore)
|
||||||
|
if err != nil {
|
||||||
|
protocols = append(protocols, bzzProto)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue