Exemplo n.º 1
0
 protected void addClient(SocketAddress clientAddr) {
   if (!containsClient(clientAddr)) {
     ClientPanel clientPanel = new ClientPanel(clientAddr.toString());
     tabbedPane.add(clientAddr.toString(), clientPanel);
     clients.put(clientAddr, clientPanel);
   }
 }
Exemplo n.º 2
0
  /** Prepares the socket addresses to attempt for the current proxy or host. */
  private void resetNextInetSocketAddress(Proxy proxy) throws UnknownHostException {
    // Clear the addresses. Necessary if getAllByName() below throws!
    inetSocketAddresses = new ArrayList<InetSocketAddress>();

    String socketHost;
    int socketPort;
    if (proxy.type() == Proxy.Type.DIRECT || proxy.type() == Proxy.Type.SOCKS) {
      socketHost = address.getUriHost();
      socketPort = getEffectivePort(uri);
    } else {
      SocketAddress proxyAddress = proxy.address();
      if (!(proxyAddress instanceof InetSocketAddress)) {
        throw new IllegalArgumentException(
            "Proxy.address() is not an " + "InetSocketAddress: " + proxyAddress.getClass());
      }
      InetSocketAddress proxySocketAddress = (InetSocketAddress) proxyAddress;
      socketHost = getHostString(proxySocketAddress);
      socketPort = proxySocketAddress.getPort();
    }

    // Try each address for best behavior in mixed IPv4/IPv6 environments.
    for (InetAddress inetAddress : network.resolveInetAddresses(socketHost)) {
      inetSocketAddresses.add(new InetSocketAddress(inetAddress, socketPort));
    }
    nextInetSocketAddressIndex = 0;
  }
 public String getLocalAddress() {
   SocketAddress address = channel.localAddress();
   if (address == null) {
     return null;
   }
   return "tcp://" + IPV6Util.encloseHost(address.toString());
 }
 public String getRemoteAddress() {
   SocketAddress address = channel.remoteAddress();
   if (address == null) {
     return null;
   }
   return address.toString();
 }
Exemplo n.º 5
0
  private void startClient(final Socket s) {
    final GitDaemonClient dc = new GitDaemonClient(this);

    final SocketAddress peer = s.getRemoteSocketAddress();
    if (peer instanceof InetSocketAddress)
      dc.setRemoteAddress(((InetSocketAddress) peer).getAddress());

    new Thread(processors, "Git-Daemon-Client " + peer.toString()) {
      public void run() {
        try {
          dc.execute(s);
        } catch (ServiceNotEnabledException e) {
          // Ignored. Client cannot use this repository.
        } catch (ServiceNotAuthorizedException e) {
          // Ignored. Client cannot use this repository.
        } catch (IOException e) {
          // Ignore unexpected IO exceptions from clients
        } finally {
          try {
            s.getInputStream().close();
          } catch (IOException e) {
            // Ignore close exceptions
          }
          try {
            s.getOutputStream().close();
          } catch (IOException e) {
            // Ignore close exceptions
          }
        }
      }
    }.start();
  }
Exemplo n.º 6
0
  /**
   * Safely returns true if a packet has the same address and a socket. Used to determine its own
   * socket.
   */
  private static boolean isSameSocketAddress(DatagramSocket socket, InetSocketAddress addr) {
    if (socket == null || addr == null) return false;

    SocketAddress socketAddr = socket.getLocalSocketAddress();

    return socketAddr != null && socketAddr.equals(addr);
  }
Exemplo n.º 7
0
 @JRubyMethod(name = {"getsockname", "__getsockname"})
 public IRubyObject getsockname(ThreadContext context) {
   SocketAddress sock = getLocalSocket();
   if (null == sock) {
     return RubySocket.pack_sockaddr_in(context, null, 0, "0.0.0.0");
   }
   return context.getRuntime().newString(sock.toString());
 }
Exemplo n.º 8
0
 @JRubyMethod(name = {"getpeername", "__getpeername"})
 public IRubyObject getpeername(ThreadContext context) {
   SocketAddress sock = getRemoteSocket();
   if (null == sock) {
     throw context.getRuntime().newIOError("Not Supported");
   }
   return context.getRuntime().newString(sock.toString());
 }
Exemplo n.º 9
0
    protected void preRouteMuleMessage(final DefaultMuleMessage message) throws Exception {
      super.preRouteMuleMessage(message);

      final SocketAddress clientAddress = socket.getRemoteSocketAddress();
      if (clientAddress != null) {
        message.setProperty(MuleProperties.MULE_REMOTE_CLIENT_ADDRESS, clientAddress.toString());
      }
    }
Exemplo n.º 10
0
 @Override
 public String getRemoteAddress() {
   final SocketAddress remoteAddress = ioSession.getRemoteAddress();
   if (remoteAddress != null) {
     return remoteAddress.toString();
   }
   return null;
 }
Exemplo n.º 11
0
 @Override
 public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
   context.getWorkers().put(ctx.getChannel(), new MasterWorkerHolder(ctx.getChannel()));
   Channel channel = ctx.getChannel();
   SocketAddress addr = channel.getRemoteAddress();
   SocketLog.info("worker connected , :" + addr.toString());
   super.channelConnected(ctx, e);
 }
Exemplo n.º 12
0
 private void checkAddressType(SocketAddress a) {
   if (a != null && !getTransportMetadata().getAddressType().isAssignableFrom(a.getClass())) {
     throw new IllegalArgumentException(
         "localAddress type: "
             + a.getClass().getSimpleName()
             + " (expected: "
             + getTransportMetadata().getAddressType().getSimpleName()
             + ")");
   }
 }
Exemplo n.º 13
0
    /**
     * @param requiresTunnel true if the HTTP connection needs to tunnel one protocol over another,
     *     such as when using HTTPS through an HTTP proxy. When doing so, we must avoid buffering
     *     bytes intended for the higher-level protocol.
     */
    public Address(URI uri, Proxy proxy, boolean requiresTunnel) {
      this.proxy = proxy;
      this.requiresTunnel = requiresTunnel;
      this.uriHost = uri.getHost();
      this.uriPort = uri.getEffectivePort();

      SocketAddress proxyAddress = proxy.address();
      if (!(proxyAddress instanceof InetSocketAddress)) {
        throw new IllegalArgumentException(
            "Proxy.address() is not an InetSocketAddress: " + proxyAddress.getClass());
      }
      InetSocketAddress proxySocketAddress = (InetSocketAddress) proxyAddress;
      this.socketHost = proxySocketAddress.getHostName();
      this.socketPort = proxySocketAddress.getPort();
    }
Exemplo n.º 14
0
 @Override
 public ChannelFuture write(Object message, SocketAddress remoteAddress) {
   if (remoteAddress == null || remoteAddress.equals(getRemoteAddress())) {
     return super.write(message);
   }
   return getUnsupportedOperationFuture();
 }
  /**
   * checks ban-lists, then white-lists, then space for the server. Returns null on success, or an
   * error message
   */
  public String allowUserToConnect(SocketAddress par1SocketAddress, String par2Str) {
    if (this.bannedPlayers.isBanned(par2Str)) {
      BanEntry var6 = (BanEntry) this.bannedPlayers.getBannedList().get(par2Str);
      String var7 = "You are banned from this server!\nReason: " + var6.getBanReason();

      if (var6.getBanEndDate() != null) {
        var7 = var7 + "\nYour ban will be removed on " + dateFormat.format(var6.getBanEndDate());
      }

      return var7;
    } else if (!this.isAllowedToLogin(par2Str)) {
      return "You are not white-listed on this server!";
    } else {
      String var3 = par1SocketAddress.toString();
      var3 = var3.substring(var3.indexOf("/") + 1);
      var3 = var3.substring(0, var3.indexOf(":"));

      if (this.bannedIPs.isBanned(var3)) {
        BanEntry var4 = (BanEntry) this.bannedIPs.getBannedList().get(var3);
        String var5 = "Your IP address is banned from this server!\nReason: " + var4.getBanReason();

        if (var4.getBanEndDate() != null) {
          var5 = var5 + "\nYour ban will be removed on " + dateFormat.format(var4.getBanEndDate());
        }

        return var5;
      } else {
        return this.playerEntityList.size() >= this.maxPlayers ? "The server is full!" : null;
      }
    }
  }
Exemplo n.º 16
0
 public void datagramReceived(
     ListenerDatagramChannel listenerDatagramChannel,
     ByteBuffer byteBuffer,
     SocketAddress address) {
   log.debug("Datagram Received on: " + address.toString());
   packetReceived(byteBuffer, address, iChannels.get(listenerDatagramChannel.hashCode()));
 }
Exemplo n.º 17
0
  /** {@inheritDoc} */
  @Override
  public final boolean listen(SocketAddress address) {
    synchronized (state) {
      // If currently connecting wait to be connected.
      if (state.equals(Disconnecting)) {
        state.waitFor(Closed);
      }
      // If closed, we can now connect.
      if (state.equals(Closed)) {
        try {
          // Attempt connection
          doBind(address);

          // Add client to server/pipeline sets.
          register();

          // Connect successful, notify.
          state.set(Accepting);
        } catch (IOException e) {
          // Notify listeners of errors
          invokeError(e);

          // "Close" the connection on error
          close();
        }
      }

      // Only successful if the binded address equals the given address.
      return address.equals(getAddress());
    }
  }
Exemplo n.º 18
0
  @JRubyMethod(name = "getpeername")
  public IRubyObject getpeername(ThreadContext context) {
    Ruby runtime = context.runtime;

    try {
      SocketAddress sock = getRemoteSocket();

      if (null == sock) {
        throw runtime.newIOError("Not Supported");
      }

      return runtime.newString(sock.toString());

    } catch (BadDescriptorException e) {
      throw runtime.newErrnoEBADFError();
    }
  }
  public void verify(final IOSession iosession, final SSLSession sslsession) throws SSLException {
    SocketAddress remoteAddress = iosession.getRemoteAddress();
    String address;
    if (remoteAddress instanceof InetSocketAddress) {
      address = ((InetSocketAddress) remoteAddress).getHostName();
    } else {
      address = remoteAddress.toString();
    }

    if (verificationManager != null) {
      try {
        verificationManager.verifyRevocationStatus(sslsession.getPeerCertificateChain());
      } catch (CertificateVerificationException e) {
        throw new SSLException("Certificate Chain Validation failed for host : " + address, e);
      }
    }
  }
Exemplo n.º 20
0
  public static String parseChannelRemoteAddr(final Channel channel) {
    if (null == channel) {
      return "";
    }
    final SocketAddress remote = channel.remoteAddress();
    final String addr = remote != null ? remote.toString() : "";

    if (addr.length() > 0) {
      int index = addr.lastIndexOf("/");
      if (index >= 0) {
        return addr.substring(index + 1);
      }

      return addr;
    }

    return "";
  }
Exemplo n.º 21
0
 @Override
 public boolean equals(Object obj) {
   if (obj instanceof MultiplexingKey) {
     MultiplexingKey obj2 = (MultiplexingKey) obj;
     return udpAddress.equals(obj2.udpAddress) && (rxpPort == obj2.rxpPort);
   } else {
     return false;
   }
 }
 /**
  * Builds the key that uniquely identifies the MBeanServerConnection that would be created by
  * this builder
  *
  * @return the unique MBeanServerConnection key
  */
 private String buildKey() {
   StringBuilder b = new StringBuilder();
   b.append(channel.getId());
   b.append(domain);
   if (remoteAddress != null) {
     b.append(remoteAddress.toString());
   }
   return b.toString();
 }
Exemplo n.º 23
0
  public void run() {
    SocketAddress addr = new InetSocketAddress(host, port);
    do {
      try {
        log.fine("try to Connect to " + addr.toString());
        socket = new Socket();
        socket.connect(addr);
        iecsock = new IECSocket(socket, iecSocketListener);
        //            	iecsock.iecSocketParameter = (IECSocketParameter) iecparam.clone();
        iecsock.iecSocketParameter = iecparam;
        iecsock.start();
        ActionEvent clientEvent =
            new ActionEvent(
                iecsock, ActionEvent.ACTION_PERFORMED, IECClientAction.IECClientConnect.toString());
        ThreadAction a = new ThreadAction(clientEvent);
        log.info("Client has connected! " + socket.getRemoteSocketAddress().toString());

        //	    		suspend();
        synchronized (o) {
          try {
            o.wait();
          } catch (InterruptedException e) {
            log.severe("wait " + e.getMessage());
            interrupt();
          }
        }

        log.finer("resume");
      } catch (IOException e) {
        log.warning(e.getMessage());
        close();
      }
      if (!isInterrupted()) waitReconnect();
    } while ((!isInterrupted()) && (socket.isClosed()));

    //       	while (!isInterrupted());
    //       	while ((!isInterrupted())&&(!socket.isConnected()));

    log.finer("exit");
    ActionEvent clientEvent =
        new ActionEvent(
            this, ActionEvent.ACTION_PERFORMED, IECClientAction.IECClientStop.toString());
    ThreadAction a = new ThreadAction(clientEvent);
  }
    @Override
    public void connect(
        ChannelHandlerContext ctx,
        SocketAddress remoteAddress,
        SocketAddress localAddress,
        ChannelPromise promise)
        throws Exception {
      final String local = localAddress == null ? "UNKNOW" : localAddress.toString();
      final String remote = remoteAddress == null ? "UNKNOW" : remoteAddress.toString();
      LOGGER.info("CLIENT : CONNECT  {} => {}", local, remote);
      super.connect(ctx, remoteAddress, localAddress, promise);

      if (channelEventListener != null) {
        assert remoteAddress != null;
        putRemotingEvent(
            new RemotingEvent(
                RemotingEventType.CONNECT, remoteAddress.toString(), new NettyChannel(ctx)));
      }
    }
Exemplo n.º 25
0
 /* 29:   */
 /* 30:   */ private String c(SocketAddress paramSocketAddress) /* 31:   */ {
   /* 32:29 */ String str = paramSocketAddress.toString();
   /* 33:30 */ if (str.contains("/")) {
     /* 34:31 */ str = str.substring(str.indexOf('/') + 1);
     /* 35:   */ }
   /* 36:33 */ if (str.contains(":")) {
     /* 37:34 */ str = str.substring(0, str.indexOf(':'));
     /* 38:   */ }
   /* 39:36 */ return str;
   /* 40:   */ }
Exemplo n.º 26
0
  public void messageReceived(final FtpIoSession session, final FtpRequest request)
      throws Exception {
    SocketAddress sa = session.getServiceAddress();
    log.debug("message received: " + sa.toString());
    if (actionListener != null) {
      actionListener.onAction(
          new Runnable() {

            public void run() {
              try {
                wrapped.messageReceived(session, request);
              } catch (Exception ex) {
                throw new RuntimeException(ex);
              }
            }
          });
    } else {
      wrapped.messageReceived(session, request);
    }
  }
Exemplo n.º 27
0
 public static void checkForNewUDPConnections() {
   SocketAddress connection = null;
   ByteBuffer bb = ByteBuffer.allocate(65507);
   try {
     while ((connection = serverUDPConChannel.receive(bb)) != null) {
       System.out.println("Position " + bb.position());
       bb.flip();
       System.out.println("Packet Received");
       System.out.println("BB LIMIT: " + bb.limit());
       for (int i = 0; i < bb.limit(); i++) {
         System.out.println("Value " + i + ": " + bb.get(i));
       }
       if (bb.array()[0] == GAME_INFO && bb.array()[1] == NetworkProtocol.GAME_INFO_HEARTBEAT)
         for (int i = 0; i < attemptedConnections.size(); i++) {
           System.out.println("1: " + connection.toString());
           System.out.println(
               "2: "
                   + attemptedConnections
                       .get(i)
                       .getTCPConnection()
                       .socket()
                       .getRemoteSocketAddress()
                       .toString());
           if (NetworkProtocol.IPsEqual(
               connection,
               attemptedConnections.get(i).getTCPConnection().socket().getRemoteSocketAddress())) {
             DatagramChannel d = DatagramChannel.open();
             d.configureBlocking(false);
             d.connect(connection);
             attemptedConnections.get(i).setUDPConnection(d);
             byte[] response = {GAME_INFO, GAME_INFO_HEARTBEAT};
             d.write(ByteBuffer.wrap(response));
             System.out.println("Equal");
           }
         }
       bb.clear();
     }
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Exemplo n.º 28
0
  /** Resets {@link #nextInetSocketAddress} to the first option. */
  private void resetNextInetSocketAddress(Proxy proxy) throws UnknownHostException {
    socketAddresses = null; // Clear the addresses. Necessary if getAllByName() below throws!

    String socketHost;
    if (proxy.type() == Proxy.Type.DIRECT) {
      socketHost = uri.getHost();
      socketPort = getEffectivePort(uri);
    } else {
      SocketAddress proxyAddress = proxy.address();
      if (!(proxyAddress instanceof InetSocketAddress)) {
        throw new IllegalArgumentException(
            "Proxy.address() is not an " + "InetSocketAddress: " + proxyAddress.getClass());
      }
      InetSocketAddress proxySocketAddress = (InetSocketAddress) proxyAddress;
      socketHost = proxySocketAddress.getHostName();
      socketPort = proxySocketAddress.getPort();
    }

    // Try each address for best behavior in mixed IPv4/IPv6 environments.
    socketAddresses = dns.getAllByName(socketHost);
    nextSocketAddressIndex = 0;
  }
  public int send(ByteBuffer src, SocketAddress target) throws IOException {
    if (src == null) throw new NullPointerException();

    synchronized (writeLock) {
      ensureOpen();
      InetSocketAddress isa = Net.checkAddress(target);
      InetAddress ia = isa.getAddress();
      if (ia == null) throw new IOException("Target address not resolved");
      synchronized (stateLock) {
        if (!isConnected()) {
          if (target == null) throw new NullPointerException();
          SecurityManager sm = System.getSecurityManager();
          if (sm != null) {
            if (ia.isMulticastAddress()) {
              sm.checkMulticast(ia);
            } else {
              sm.checkConnect(ia.getHostAddress(), isa.getPort());
            }
          }
        } else { // Connected case; Check address then write
          if (!target.equals(remoteAddress)) {
            throw new IllegalArgumentException("Connected address not equal to target address");
          }
          return write(src);
        }
      }

      int n = 0;
      try {
        begin();
        if (!isOpen()) return 0;
        writerThread = NativeThread.current();
        do {
          n = send(fd, src, isa);
        } while ((n == IOStatus.INTERRUPTED) && isOpen());

        synchronized (stateLock) {
          if (isOpen() && (localAddress == null)) {
            localAddress = Net.localAddress(fd);
          }
        }
        return IOStatus.normalize(n);
      } finally {
        writerThread = 0;
        end((n > 0) || (n == IOStatus.UNAVAILABLE));
        assert IOStatus.check(n);
      }
    }
  }
Exemplo n.º 30
0
    public HttpWorker(Socket socket) throws IOException {
      String encoding = endpoint.getEncoding();
      if (encoding == null) {
        encoding = MuleServer.getMuleContext().getConfiguration().getDefaultEncoding();
      }

      conn = new HttpServerConnection(socket, encoding, (HttpConnector) connector);

      cookieSpec =
          MapUtils.getString(
              endpoint.getProperties(),
              HttpConnector.HTTP_COOKIE_SPEC_PROPERTY,
              ((HttpConnector) connector).getCookieSpec());
      enableCookies =
          MapUtils.getBooleanValue(
              endpoint.getProperties(),
              HttpConnector.HTTP_ENABLE_COOKIES_PROPERTY,
              ((HttpConnector) connector).isEnableCookies());

      final SocketAddress clientAddress = socket.getRemoteSocketAddress();
      if (clientAddress != null) {
        remoteClientAddress = clientAddress.toString();
      }
    }