예제 #1
0
  /** Determines if we're connected to the given host. */
  public boolean isConnectedTo(InetAddress host) {
    UDPSocketChannel[] array = _channels;

    if (_lastConnectionID == 0) return false;
    for (int i = 0; i < array.length; i++) {
      UDPSocketChannel channel = array[i];
      if (channel != null && host.equals(channel.getRemoteSocketAddress().getAddress())) {
        return true;
      }
    }
    return false;
  }
예제 #2
0
  /**
   * Route a message to the {@link UDPConnectionProcessor} identified via the message's connection
   * ID. Notifies the provided listener (if any) if the channel is ready to produce events.
   */
  public void routeMessage(RUDPMessage msg, InetSocketAddress addr) {
    UDPSocketChannel[] array = _channels;
    int connID = msg.getConnectionID() & 0xff;
    UDPSocketChannel channel = null;
    // If connID equals 0 and SynMessage then associate with a connection
    // that appears to want it (connecting and with knowledge of it).
    if (connID == 0 && msg instanceof SynMessage) {
      LOG.debugf("route sym: {0}", msg);
      for (int i = 1; i < array.length; i++) {
        channel = array[i];
        if (channel == null) continue;

        LOG.debugf("non-empty index: {0}, addr: {1}", i, channel.getRemoteSocketAddress());

        if (channel.isConnectionPending() && channel.isForMe(addr, (SynMessage) msg)) {
          LOG.debugf(
              "found index: {0}, sender id: {1}", i, ((SynMessage) msg).getSenderConnectionID());
          channel.getProcessor().handleMessage(msg);
          break;
        }
      }
      // Note: eventually these messages should find a match
      // so it is safe to throw away premature ones

    } else if (array[connID] != null) { // If valid connID then send on to connection
      channel = array[connID];
      if (msg instanceof SynMessage) {
        LOG.debugf("already assigned syn: {0}", msg);
      }
      if (channel.getRemoteSocketAddress().equals(addr)) channel.getProcessor().handleMessage(msg);
    } else {
      LOG.debugf("message for non-existing connection: {0}", msg);
    }

    if (channel != null && channel.getProcessor().readyOps() != 0)
      context.getTransportListener().eventPending();
  }