-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Decouple peer info from PeerActor (WIP)
- Loading branch information
Nicolas Tallar
committed
May 18, 2017
1 parent
1b51794
commit 1b7e2c1
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
src/main/scala/io/iohk/ethereum/network/PeerInfoManager.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package io.iohk.ethereum.network | ||
|
||
import akka.actor.{Actor, ActorLogging, ActorRef} | ||
import io.iohk.ethereum.network.PeerMessageBusActor.{MessageClassifier, MessageFromPeer, PeerSelector, Subscribe} | ||
import io.iohk.ethereum.network.p2p.Message | ||
|
||
/** | ||
* Handles | ||
* - Updating max block per peer | ||
* - Total difficulty per peer | ||
* - Fork accepted | ||
* Should now: | ||
* - When peers die? | ||
* - When peers are created? | ||
*/ | ||
class PeerInfoManager(peerMessageBus: ActorRef) extends Actor with ActorLogging { | ||
|
||
//Subscribe to msgs | ||
val messageCodes = Set[Int]() //FIXME | ||
val subsMessage = MessageClassifier(messageCodes, PeerSelector.AllPeers) | ||
peerMessageBus ! Subscribe(subsMessage) | ||
|
||
//Save data | ||
val peersInfo: Map[PeerId, PeerInfo] = ??? | ||
case class PeerInfo(maxBlockNumber: BigInt, totalDifficulty: BigInt, forkAccepted: Boolean) | ||
//FIXME: Could it be the same that PeerInfo from Handshaker? | ||
|
||
//Process data | ||
def updateMaxBlock(message: Message, peerId: PeerId, peerInfo: PeerInfo): PeerInfo = ??? | ||
def updateTotalDifficulty(message: Message, peerId: PeerId, peerInfo: PeerInfo): PeerInfo = ??? | ||
def updateForkAccepted(message: Message, peerId: PeerId, peerInfo: PeerInfo): PeerInfo = ??? | ||
|
||
override def receive: Receive = updatePeerInfo(Map.empty) | ||
|
||
def updatePeerInfo(peersInfo: Map[PeerId, PeerInfo]): Receive = { | ||
case MessageFromPeer(msg, peerId) => | ||
val oldPeerInfoOpt = peersInfo.get(peerId) | ||
oldPeerInfoOpt.foreach{ oldPeerInfo => | ||
val peerInfoMaxBlockNumberUpdated = updateMaxBlock(msg, peerId, oldPeerInfo) | ||
val peerInfoTDUpdated = updateMaxBlock(msg, peerId, peerInfoMaxBlockNumberUpdated) | ||
val newPeerInfo = updateMaxBlock(msg, peerId, peerInfoTDUpdated) | ||
context become updatePeerInfo(peersInfo + (peerId -> newPeerInfo)) | ||
} | ||
|
||
} | ||
|
||
} |