예제 #1
0
  @Override
  public void execute(Packet in) throws IOException {
    Friend f = con.getRemoteFriend();
    if (f == null) {
      // this can happen when a friend is removed using the UI. Just blow this connection away.
      con.close();
      return;
    }
    boolean guidMismatch = false;
    int remoteGUID = in.readInt();
    if (remoteGUID != f.getGuid()) {
      if (T.t) {
        T.warn("GUID mismatch!!! Closing connection.");
      }
      //            f.setGuid(remoteGUID);
      guidMismatch = true;
    }

    int port = in.readInt();
    f.updateLastKnownHostInfo(
        manager.getNetMan().getSocketFor(con).getInetAddress().getHostAddress(), port);
    f.setShareSize(in.readLong());
    int buildNumber = in.readInt();
    f.setAllianceBuildNumber(buildNumber);

    if (CoreSubsystem.ALLOW_TO_SEND_UPGRADE_TO_FRIENDS) {
      if (buildNumber < Version.BUILD_NUMBER && buildNumber > 1120) {
        // remote has old version
        Hash h = core.getFileManager().getAutomaticUpgrade().getMyJarHash();
        if (h != null) {
          send(new NewVersionAvailable(h));
        }
      }
    }

    // now that we have a good connection to friend: verify that we only have ONE connection
    if (con.getRemoteFriend().hasMultipleFriendConnections()) {
      if (T.t) {
        T.trace(
            "Has multple connections to a friend. Figuring out wich one of us should close the connection");
      }
      if ((con.getDirection() == Connection.Direction.IN
              && con.getRemoteUserGUID() > manager.getMyGUID())
          || (con.getDirection() == Connection.Direction.OUT
              && manager.getMyGUID() > con.getRemoteUserGUID())) {
        // serveral connections. Its up to us to close one
        if (T.t) {
          T.info("Already connected to " + con.getRemoteFriend() + ". Closing connection");
        }
        send(new GracefulClose(GracefulClose.DUPLICATE_CONNECTION));
        // con.close();
        // close connection when we in turn receive a graceful close
      }
    }
    if (guidMismatch) {
      send(new GracefulClose(GracefulClose.GUID_MISMATCH));
    } else {
      // this is the place for an event: "FriendSuccessfullyConnected".
      core.getNetworkManager().signalFriendConnected(con.getRemoteFriend());

      core.getUICallback().nodeOrSubnodesUpdated(con.getRemoteFriend());
    }
  }
예제 #2
0
  @Override
  public void execute(Packet in) throws IOException {
    Friend f = con.getRemoteFriend();

    boolean guidMismatch = false;
    int remoteGUID = in.readInt();
    if (remoteGUID != f.getGuid()) {
      if (T.t) {
        T.warn("GUID mismatch!!! Closing connection.");
      }
      //            f.setGuid(remoteGUID);
      guidMismatch = true;
    }

    int port = in.readInt();
    f.updateLastKnownHostInfo(
        manager.getNetMan().getSocketFor(con).getInetAddress().getHostAddress(), port);
    f.setShareSize(in.readLong());
    int buildNumber = in.readInt();
    f.setAllianceBuildNumber(buildNumber);
    f.setTotalBytesReceived(in.readLong());
    f.setTotalBytesSent(in.readLong());
    f.setHighestIncomingCPS(in.readInt());
    f.setHighestOutgoingCPS(in.readInt());
    f.setNumberOfFilesShared(in.readInt());
    f.setNumberOfInvitedFriends(in.readInt());
    try {
      String dnsName = in.readUTF();
      if (!dnsName.trim().isEmpty()) {
        f.updateLastKnownHostInfo(dnsName, port);
      }
    } catch (BufferUnderflowException ex) {
    }

    if (CoreSubsystem.ALLOW_TO_SEND_UPGRADE_TO_FRIENDS) {
      if (buildNumber < Version.BUILD_NUMBER && buildNumber > 1120) {
        // remote has old version
        Hash h = core.getFileManager().getAutomaticUpgrade().getMyJarHash();
        if (h != null) {
          send(new NewVersionAvailable(h));
        }
      }
    }

    // now that we have a good connection to friend: verify that we only have ONE connection
    if (con.getRemoteFriend().hasMultipleFriendConnections()) {
      if (T.t) {
        T.trace(
            "Has multple connections to a friend. Figuring out wich one of us should close the connection");
      }
      if ((con.getDirection() == Connection.Direction.IN
              && con.getRemoteUserGUID() > manager.getMyGUID())
          || (con.getDirection() == Connection.Direction.OUT
              && manager.getMyGUID() > con.getRemoteUserGUID())) {
        // serveral connections. Its up to us to close one
        if (T.t) {
          T.info("Already connected to " + con.getRemoteFriend() + ". Closing connection");
        }
        send(new GracefulClose(GracefulClose.DUPLICATE_CONNECTION));
        // con.close();
        // close connection when we in turn receive a graceful close
      }
    }
    if (guidMismatch) {
      send(new GracefulClose(GracefulClose.GUID_MISMATCH));
    } else {
      // this is the place for an event: "FriendSuccessfullyConnected".
      core.getNetworkManager().signalFriendConnected(con.getRemoteFriend());
      core.getUICallback().nodeOrSubnodesUpdated(con.getRemoteFriend());
      core.updateLastSeenOnlineFor(con.getRemoteFriend());
      System.setProperty("alliance.network.friendsonline", "" + manager.getNFriendsConnected());
    }
  }