improve documentation

This commit is contained in:
zelig 2015-05-29 11:44:45 +01:00
parent 7c05778cca
commit f93fe2b086
2 changed files with 17 additions and 13 deletions

View file

@ -30,10 +30,11 @@ on top of the dpa
it is the public interface of the dpa which is included in the ethereum stack it is the public interface of the dpa which is included in the ethereum stack
*/ */
type Api struct { type Api struct {
Chunker *TreeChunker
Port string
Resolver *resolver.Resolver
dpa *DPA dpa *DPA
netStore *netStore netStore *netStore
port string
Resolver *resolver.Resolver
} }
/* /*
@ -42,18 +43,21 @@ the api constructor initialises
- the chunker (bzz hash) - the chunker (bzz hash)
- the dpa - single document retrieval api - the dpa - single document retrieval api
*/ */
func NewApi(datadir, port string) (api *Api, err error) { func NewApi(datadir, port string) (self *Api, err error) {
api = &Api{port: port} self = &Api{
Chunker: &TreeChunker{},
Port: port,
}
api.netStore, err = newNetStore(filepath.Join(datadir, "bzz"), filepath.Join(datadir, "bzzpeers.json")) self.netStore, err = newNetStore(filepath.Join(datadir, "bzz"), filepath.Join(datadir, "bzzpeers.json"))
if err != nil { if err != nil {
return return
} }
api.dpa = &DPA{ self.dpa = &DPA{
Chunker: &TreeChunker{}, Chunker: self.Chunker,
ChunkStore: api.netStore, ChunkStore: self.netStore,
} }
return return
} }
@ -65,20 +69,21 @@ func (self *Api) Bzz() (p2p.Protocol, error) {
/* /*
Start is called when the ethereum stack is started Start is called when the ethereum stack is started
- calls Init() on treechunker
- launches the dpa (listening for chunk store/retrieve requests) - launches the dpa (listening for chunk store/retrieve requests)
- launches the netStore (starts kademlia hive peer management) - launches the netStore (starts kademlia hive peer management)
- starts an http server - starts an http server
*/ */
func (self *Api) Start(node *discover.Node, connectPeer func(string) error) { func (self *Api) Start(node *discover.Node, connectPeer func(string) error) {
self.Chunker.Init()
self.dpa.start() self.dpa.Start()
self.netStore.start(node, connectPeer) self.netStore.start(node, connectPeer)
dpaLogger.Infof("Swarm started.") dpaLogger.Infof("Swarm started.")
go startHttpServer(self, self.port) go startHttpServer(self, self.Port)
} }
func (self *Api) Stop() { func (self *Api) Stop() {
self.dpa.stop() self.dpa.Stop()
self.netStore.stop() self.netStore.stop()
} }

View file

@ -104,7 +104,6 @@ func (self *DPA) Start() {
if self.running { if self.running {
return return
} }
self.Chunker.Init()
self.running = true self.running = true
self.quitC = make(chan bool) self.quitC = make(chan bool)
self.storeLoop() self.storeLoop()