Esempio n. 1
1
 private void updatePeer(
     final Peer peer,
     final InetSocketAddress isa,
     final Type type,
     final LanternTrafficCounter trafficCounter) {
   // We can get multiple notifications for the same peer, in which case
   // they'll already have a counter.
   if (peer.getTrafficCounter() == null) {
     log.debug("Setting traffic counter...");
     peer.setTrafficCounter(trafficCounter);
   } else {
     log.debug("Peer already has traffic counter...");
   }
   final String address = isa.getAddress().getHostAddress();
   if (StringUtils.isBlank(peer.getIp())) {
     peer.setIp(address);
   }
   if (peer.getPort() == 0) {
     peer.setPort(isa.getPort());
   }
   if (peer.getRosterEntry() == null) {
     log.debug("Setting roster entry");
     final URI uri = LanternUtils.newURI(peer.getPeerid());
     peer.setRosterEntry(rosterEntry(uri));
   }
   peer.setType(type.toString());
   updateGeoData(peer, isa.getAddress());
   // Note we don't sync peers with the frontend here because the timer
   // will do it for us
 }
Esempio n. 2
0
 @Subscribe
 public void onKscopeAd(final KscopeAdEvent event) {
   final LanternKscopeAdvertisement ad = event.getAd();
   // It is possible and even likely we already know about this peer
   // through some other means, in which case we have to update the data
   // about that peer as necessary.
   log.debug("Adding peer through kscope ad...");
   final String jid = ad.getJid();
   final URI uri = LanternUtils.newURI(jid);
   final Peer existing = this.model.getPeerCollector().getPeer(uri);
   final LanternRosterEntry entry = this.roster.getRosterEntry(jid);
   if (existing == null) {
     // The following can be null.
     final Peer peer =
         new Peer(
             uri,
             "",
             ad.hasMappedEndpoint(),
             0,
             0,
             Type.pc,
             ad.getAddress(),
             ad.getPort(),
             Mode.give,
             false,
             null,
             entry);
     this.model.getPeerCollector().addPeer(uri, peer);
     updateGeoData(peer, ad.getAddress());
   } else {
     existing.setIp(ad.getAddress());
     existing.setPort(ad.getPort());
     existing.setMode(Mode.give);
     existing.setMapped(ad.hasMappedEndpoint());
     if (existing.getRosterEntry() == null) {
       // Ours could be null too, but can't hurt to set.
       existing.setRosterEntry(entry);
     }
     existing.setVersion(ad.getLanternVersion());
     updateGeoData(existing, ad.getAddress());
   }
 }