public void handle(PeerMessage event) { PeerAddress oldFriend; PeerAddress sender = event.getMSPeerSource(); PeerAddress newFriend = event.getNewFriend(); // add the sender address to the list of friends if (!friends.contains(sender)) { if (friends.size() == viewSize) { oldFriend = friends.get(rand.nextInt(viewSize)); friends.remove(oldFriend); fdUnregister(oldFriend); Snapshot.removeFriend(serverPeerAddress, oldFriend); } friends.addElement(sender); fdRegister(sender); Snapshot.addFriend(serverPeerAddress, sender); } // add the received new friend from the sender to the list of friends if (!friends.contains(newFriend) && !serverPeerAddress.equals(newFriend)) { if (friends.size() == viewSize) { oldFriend = friends.get(rand.nextInt(viewSize)); friends.remove(oldFriend); fdUnregister(oldFriend); Snapshot.removeFriend(serverPeerAddress, oldFriend); } friends.addElement(newFriend); fdRegister(newFriend); Snapshot.addFriend(serverPeerAddress, newFriend); } }
public void handle(BootstrapResponse event) { if (!bootstrapped) { bootstrapped = true; PeerAddress peer; Set<PeerEntry> somePeers = event.getPeers(); for (PeerEntry peerEntry : somePeers) { peer = (PeerAddress) peerEntry.getOverlayAddress(); friends.addElement(peer); fdRegister(peer); } trigger( new BootstrapCompleted("Lab0", serverPeerAddress), bootstrap.getPositive(P2pBootstrap.class)); Snapshot.addFriends(serverPeerAddress, friends); SchedulePeriodicTimeout spt = new SchedulePeriodicTimeout(msgPeriod, msgPeriod); spt.setTimeoutEvent(new SendMessage(spt)); trigger(spt, timer); } }
public void handle(StartServer event) { Snapshot.addPeer(serverPeerAddress); BootstrapRequest request = new BootstrapRequest("Lab0", viewSize); trigger(request, bootstrap.getPositive(P2pBootstrap.class)); }