Пример #1
0
  private BrahmsMessage fillMessage(int message_type) {

    BrahmsMessage bmsg = new BrahmsMessage();

    if (brahmsGlobalVars.getLocalView().getRandomPeerFromLocalViewList() != null) {

      bmsg.type = message_type;

      // if it is a push request
      if (message_type == BrahmsGlobalVars.PUSH_REQUEST) {
        bmsg.numPeers = 1;
        bmsg.peers = new PeerIdentity[bmsg.numPeers];
        bmsg.peers[0] = brahmsGlobalVars.getUserPeerIdentity();
        bmsg.sentFrom = brahmsGlobalVars.getUserPeerIdentity();
      }
      // if it is a pull request
      else if (message_type == brahmsGlobalVars.PULL_REQUEST) {
        bmsg.numPeers = 0;
        bmsg.sentFrom = brahmsGlobalVars.getUserPeerIdentity();
      }
      // if it is a pull response
      else if (message_type == brahmsGlobalVars.PULL_RESPONCE) {
        bmsg.numPeers =
            brahmsGlobalVars
                .getLocalView()
                .size(); // (int) (localView.LocalViewSize() * BrahmsMessageHandler.BETTA);
        // might cause a problem. shoud the array be initialized before?
        bmsg.peers = brahmsGlobalVars.getLocalView().returnLocalViewList();
        bmsg.sentFrom = brahmsGlobalVars.getUserPeerIdentity();
      } else throw new RuntimeException("Parameter @type is out of range [1-3]");

    } else throw new RuntimeException("LocalView is empty. Returned null.");
    return bmsg;
  }
Пример #2
0
  private void sendMessage(final int message_type, PeerIdentity sendToPeerIdentity) {
    // TO CHANGE!! ONLY FOR TESTING PURPOSES!
    sendToPeerIdentity = brahmsGlobalVars.getUserPeerIdentity();

    System.out.println("Sending to: " + sendToPeerIdentity.toString());
    System.out.println(
        "Do we know this peer?: "
            + brahmsGlobalVars.getLocalView().containsPeer(sendToPeerIdentity));

    if (type == brahmsGlobalVars.PULL_REQUEST) {
      String key = new HashCode().toString();
      brahmsGlobalVars.addMessage(sendToPeerIdentity.toString());
    }

    // transport.tryConnect(sendToPeerIdentity,new
    // BrahmsTryConnectCallback(sendToPeerIdentity,message_type));
    brahmsGlobalVars
        .getBrahmsTransort()
        .tryConnect(
            sendToPeerIdentity, new BrahmsTryConnectCallback(sendToPeerIdentity, message_type));
  }