Пример #1
0
 protected void dataArriveAtUpPort(Object data_, Port upPort_) {
   try {
     if (upPort_ == null || ((ByteStreamContract.Message) data_).isReport())
       tcpsink.dataArriveAtUpPort(data_, upPort_);
     else super.dataArriveAtUpPort(data_, upPort_);
   } catch (Exception e_) {
     if (e_ instanceof ClassCastException)
       error(data_, "dataArriveAtUpPort()", upPort, "unrecognized data: " + e_);
     else e_.printStackTrace();
   }
 }
  /*
   *
   *   Date      By	Description
   * MM/DD/YYYY
   * ----------  --	-----------
   * 04/28/2004  INB	Created.
   *
   */
  public AddressPermissions(String stringI) throws java.lang.Exception {
    super();

    int eql = stringI.indexOf("=");

    if (eql == -1) {
      // If there is no equals (=), then the entire thing is the
      // address.
      setAddress(stringI);

    } else if (eql == 0) {
      // No actual address was provided.
      throw new java.lang.IllegalArgumentException("No address provided in " + stringI);

    } else {
      // Otherwise, we have permissions as well as an address.
      String permString = stringI.substring(eql + 1);

      if (permString.length() == 0) {
        // If there are no permissions provided, then that's an
        // error.
        throw new java.lang.IllegalArgumentException(
            "No permissions provided with address " + "epecification " + stringI);
      }

      // Turn on the appropriate permissions bits.
      setPermissions(0x00);
      char permChar;
      int idx1;

      for (int idx = 0; idx < permString.length(); ++idx) {
        // Determine which permission is being granted by each
        // character in the permissions string.
        permChar = permString.charAt(idx);

        // Find the matching access character.
        for (idx1 = 0; idx1 < ACCESS_VALUES.length; ++idx1) {
          if (permChar == ACCESS_VALUES[idx1]) {
            break;
          }
        }

        if (idx1 == ACCESS_VALUES.length) {
          // No matching character was found, throw an exception.
          throw new java.lang.IllegalArgumentException(
              "Unrecognized permission access character in " + stringI);
        }

        // Set the corresponding bit.
        setPermissions(getPermissions() | (0x01 << idx1));
      }

      // Set the address.
      setAddress(stringI.substring(0, eql));
    }

    if (getAddress().equals("*")) {
      // If this is the default wildcard address, then use the
      // default wildcard.
      setWildcard(AddressAuthorization.Wildcard);

    } else if (getAddress().equalsIgnoreCase("localhost")) {
      // If the address is localhost, then map it to the actual localhost
      // address.
      if (Localhost == null) {
        Localhost = TCP.buildAddress("localhost");
        Localhost = Localhost.substring(6, com.rbnb.compat.Utilities.lastIndexOf(Localhost, ":"));
        Localhost_Wildcard = new com.rbnb.utility.Wildcards(Localhost);
      }
      setAddress(Localhost);
      setWildcard(Localhost_Wildcard);

    } else {
      // Otherwise, create a new wildcard.
      setWildcard(new com.rbnb.utility.Wildcards(getAddress()));
    }
  }
Пример #3
0
 // this function takes the current input and returns the next state the client should be in
 public State process(
     String input,
     TCP tcp,
     UDPSender us,
     Message udpMessage,
     Message tcpMessage,
     long timeEnteredState,
     boolean firstCall) {
   if (firstCall) {
     // if its the first time in this state print messages
     System.out.println(
         "You are disconnected. To attempt to automatically find a chatter locally, type :local <username>");
     System.out.println(
         "To talk to someone in particular use the :ip <ip address> or the :host <host name> commands");
   }
   // if there is a connection go to the appropriate connected state
   if (tcp.getActive() == true) {
     if (tcp.initiator) {
       return new ConnectedInitiator();
     } else {
       return new ConnectedReceiver();
     }
   }
   // if you give an ip command
   // CLIENT
   else if (input.startsWith(":ip ")) {
     // if there was no argument
     if (input.length() < 5) {
       System.out.println("An argument is required");
       return this;
     }
     // if the connection failed
     else if (0 > tcp.connect(input.substring(4))) {
       System.out.println("Unable to connect to IP address");
     }
     return this;
   }
   // if the host command was given do the same as ip but with a longer offset
   // CLIENT
   else if (input.startsWith(":host ")) {
     if (input.length() < 7) {
       System.out.println("An argument is required");
       return this;
     }
     if (0 > tcp.connect(input.substring(6))) {
       System.out.println("Unable to connect to IP address");
     }
     return this;
   }
   // if the local command is given
   // EC Extra Credit
   else if (input.startsWith(":local ")) {
     // check to make sure it has the proper arugments
     if (input.length() < 8) {
       System.out.println("An argument is required");
       return this;
     }
     try {
       // gather the data
       String senderUsername = User.getUserName();
       String targetUsername = input.substring(7);
       String ip = tcp.getIP();
       // send a message requesting a callback from the username given as an argument
       UDPBroadcastMessage message =
           new UDPBroadcastMessage(
               1, (long) 144, (long) 0, "", senderUsername, targetUsername, ip);
       us.sendMessage(message);
     } catch (IOException e) {
     }
     return new Waiting();
   }
   // if its any other command
   else if (input.startsWith(":")) {
     System.out.println("Invalid command");
     return this;
   }
   // if they typing is not a command
   else if (!input.equals("")) {
     System.out.println("You cannot chat in this state");
     return this;
   }
   // if you recieve a UDP broadcast
   else if (udpMessage instanceof UDPBroadcastMessage && udpMessage.getCorrect()) {
     UDPBroadcastMessage m = (UDPBroadcastMessage) udpMessage;
     // if the requested user is you
     if (m.targetUsername.trim().equals(User.userName.trim())) {
       // print a message and go to user confirm callback
       System.out.println(
           "Received a broadcast with to your username from "
               + m.senderUsername
               + " at "
               + m.senderIP);
       // store the senders ip for use later
       tcp.pendingIP = m.senderIP;
       return new UserConfirmCallback();
     }
     return this;
   } else {
     return this;
   }
 }
Пример #4
0
 public void duplicate(Object source_) {
   super.duplicate(source_);
 }
Пример #5
0
 public void reset() {
   super.reset();
   tcpsink.reset();
 }
Пример #6
0
 public void setPeer(long peer_) {
   super.setPeer(peer_);
   tcpsink.peer = peer_;
 }
Пример #7
0
 public void setSackEnabled(boolean sack_) {
   super.setSackEnabled(sack_);
   tcpsink.setSackEnabled(sack_);
 }
Пример #8
0
 public void setMSS(int mss) {
   super.setMSS(mss);
   tcpsink.setMSS(mss);
 }
Пример #9
0
 public void setTTL(int ttl) {
   super.setTTL(ttl);
   tcpsink.setTTL(ttl);
 }