Skip to content

Commit

Permalink
Merge pull request ethereum#3413 from zsfelfoldi/light-topic4
Browse files Browse the repository at this point in the history
les, p2p/discv5: implement server pool, improve peer selection, light fetcher and topic searching
  • Loading branch information
fjl authored Dec 12, 2016
2 parents ee445a2 + f12f8a6 commit a98e8c0
Show file tree
Hide file tree
Showing 21 changed files with 1,913 additions and 546 deletions.
2 changes: 2 additions & 0 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ type Config struct {

type LesServer interface {
Start(srvr *p2p.Server)
Synced()
Stop()
Protocols() []p2p.Protocol
}
Expand Down Expand Up @@ -145,6 +146,7 @@ type Ethereum struct {

func (s *Ethereum) AddLesServer(ls LesServer) {
s.lesServer = ls
s.protocolManager.lesServer = ls
}

// New creates a new Ethereum object (including the
Expand Down
4 changes: 3 additions & 1 deletion eth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ type ProtocolManager struct {
quitSync chan struct{}
noMorePeers chan struct{}

lesServer LesServer

// wait group is used for graceful shutdowns during downloading
// and processing
wg sync.WaitGroup
Expand Down Expand Up @@ -171,7 +173,7 @@ func NewProtocolManager(config *params.ChainConfig, fastSync bool, networkId int
return blockchain.CurrentBlock().NumberU64()
}
inserter := func(blocks types.Blocks) (int, error) {
atomic.StoreUint32(&manager.synced, 1) // Mark initial sync done on any fetcher import
manager.setSynced() // Mark initial sync done on any fetcher import
return manager.insertChain(blocks)
}
manager.fetcher = fetcher.New(blockchain.GetBlockByHash, validator, manager.BroadcastBlock, heighter, inserter, manager.removePeer)
Expand Down
9 changes: 8 additions & 1 deletion eth/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (pm *ProtocolManager) synchronise(peer *peer) {
if err := pm.downloader.Synchronise(peer.id, pHead, pTd, mode); err != nil {
return
}
atomic.StoreUint32(&pm.synced, 1) // Mark initial sync done
pm.setSynced() // Mark initial sync done

// If fast sync was enabled, and we synced up, disable it
if atomic.LoadUint32(&pm.fastSync) == 1 {
Expand All @@ -192,3 +192,10 @@ func (pm *ProtocolManager) synchronise(peer *peer) {
}
}
}

// setSynced sets the synced flag and notifies the light server if present
func (pm *ProtocolManager) setSynced() {
if atomic.SwapUint32(&pm.synced, 1) == 0 && pm.lesServer != nil {
pm.lesServer.Synced()
}
}
Loading

0 comments on commit a98e8c0

Please sign in to comment.