示例#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);
   }
 }
示例#2
0
 public void datagramReceived(
     ListenerDatagramChannel listenerDatagramChannel,
     ByteBuffer byteBuffer,
     SocketAddress address) {
   log.debug("Datagram Received on: " + address.toString());
   packetReceived(byteBuffer, address, iChannels.get(listenerDatagramChannel.hashCode()));
 }
  /**
   * 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;
      }
    }
  }
示例#4
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();
  }
 public String getRemoteAddress() {
   SocketAddress address = channel.remoteAddress();
   if (address == null) {
     return null;
   }
   return address.toString();
 }
 public String getLocalAddress() {
   SocketAddress address = channel.localAddress();
   if (address == null) {
     return null;
   }
   return "tcp://" + IPV6Util.encloseHost(address.toString());
 }
示例#7
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());
      }
    }
 @Override
 public String getRemoteAddress() {
   final SocketAddress remoteAddress = ioSession.getRemoteAddress();
   if (remoteAddress != null) {
     return remoteAddress.toString();
   }
   return null;
 }
示例#9
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());
 }
示例#10
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);
 }
示例#11
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());
 }
 /**
  * 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();
 }
示例#13
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:   */ }
    @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)));
      }
    }
示例#15
0
  private static String getSocketAddress(SocketAddress socketAddress) {
    String address = socketAddress.toString();
    int addressLength = address.length();

    if (addressLength > 0) {
      if (address.startsWith("/")) {
        return address.substring(1);
      } else {
        int delimeterIndex = address.indexOf("/");
        if (delimeterIndex != -1 && delimeterIndex < addressLength) {
          return address.substring(address.indexOf("/") + 1);
        }
      }
    }
    return address;
  }
 public String func_72399_a(SocketAddress p_72399_1_, String p_72399_2_) {
   if (field_72401_g.func_73704_a(p_72399_2_)) {
     BanEntry banentry = (BanEntry) field_72401_g.func_73712_c().get(p_72399_2_);
     String s1 =
         (new StringBuilder())
             .append("You are banned from this server!\nReason: ")
             .append(banentry.func_73686_f())
             .toString();
     if (banentry.func_73680_d() != null) {
       s1 =
           (new StringBuilder())
               .append(s1)
               .append("\nYour ban will be removed on ")
               .append(field_72403_e.format(banentry.func_73680_d()))
               .toString();
     }
     return s1;
   }
   if (!func_72370_d(p_72399_2_)) {
     return "You are not white-listed on this server!";
   }
   String s = p_72399_1_.toString();
   s = s.substring(s.indexOf("/") + 1);
   s = s.substring(0, s.indexOf(":"));
   if (field_72413_h.func_73704_a(s)) {
     BanEntry banentry1 = (BanEntry) field_72413_h.func_73712_c().get(s);
     String s2 =
         (new StringBuilder())
             .append("Your IP address is banned from this server!\nReason: ")
             .append(banentry1.func_73686_f())
             .toString();
     if (banentry1.func_73680_d() != null) {
       s2 =
           (new StringBuilder())
               .append(s2)
               .append("\nYour ban will be removed on ")
               .append(field_72403_e.format(banentry1.func_73680_d()))
               .toString();
     }
     return s2;
   }
   if (field_72404_b.size() >= field_72405_c) {
     return "The server is full!";
   } else {
     return null;
   }
 }
示例#17
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);
      }
    }
  }
  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 "";
  }
示例#20
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);
  }
  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);
    }
  }
 public OcsConnection(final String domain, final OcsAccount account, int key) {
   this.domain = domain;
   this.addr = Util.cast2SocketAddress(domain);
   this.account = account;
   this.setKey(key);
   if (account.isExemptPassword() == false) {
     this.plainHandler = new OcsPlainHandler(account.getUsername(), account.getPassword());
     mech = new String[] {"PLAIN"};
     try {
       SaslClient sc =
           Sasl.createSaslClient(mech, null, "memcached", addr.toString(), null, plainHandler);
       evaluate = sc.evaluateChallenge(/* empty bytes */ new byte[0]);
       mechanism = sc.getMechanismName();
     } catch (SaslException e) {
       logger.error("SaslClient exception", e);
       throw new RuntimeException("SaslClient exception", e);
     }
   }
   channel = null;
 }
  private synchronized boolean send(byte[] bytes) {
    // buffering
    if (pendings.position() + bytes.length > pendings.capacity()) {
      if (!flushBuffer()) {
        LOG.error("Cannot send logs to " + server.toString());
        return false;
      }
    }
    pendings.put(bytes);

    // suppress reconnection burst
    if (!reconnector.enableReconnection(System.currentTimeMillis())) {
      return true;
    }

    // send pending data
    flush();

    return true;
  }
 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();
   }
 }
示例#25
0
  NettyClientTransport(
      SocketAddress address,
      Class<? extends Channel> channelType,
      EventLoopGroup group,
      ProtocolNegotiator negotiator,
      int flowControlWindow) {
    Preconditions.checkNotNull(negotiator, "negotiator");
    this.address = Preconditions.checkNotNull(address, "address");
    this.group = Preconditions.checkNotNull(group, "group");
    this.channelType = Preconditions.checkNotNull(channelType, "channelType");
    this.flowControlWindow = flowControlWindow;

    if (address instanceof InetSocketAddress) {
      InetSocketAddress inetAddress = (InetSocketAddress) address;
      authority = new AsciiString(inetAddress.getHostString() + ":" + inetAddress.getPort());
    } else {
      // Specialized address types are allowed to support custom Channel types so just assume their
      // toString() values are valid :authority values
      authority = new AsciiString(address.toString());
    }

    handler = newHandler();
    negotiationHandler = negotiator.newHandler(handler);
  }
示例#26
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();
      }
    }
 public void setRemoteAddr(SocketAddress socketAddress) {
   this.remoteAddr = socketAddress.toString().split(":")[0].substring(1);
 }
  public void test_setReuseAddressZ() throws Exception {
    // set up server and connect
    InetSocketAddress anyAddress = new InetSocketAddress(InetAddress.getLocalHost(), 0);
    ServerSocket serverSocket = new ServerSocket();
    serverSocket.setReuseAddress(false);
    serverSocket.bind(anyAddress);
    SocketAddress theAddress = serverSocket.getLocalSocketAddress();

    // make a connection to the server, then close the server
    Socket theSocket = new Socket();
    theSocket.connect(theAddress);
    Socket stillActiveSocket = serverSocket.accept();
    serverSocket.close();

    // now try to rebind the server which should fail with
    // setReuseAddress to false. On windows platforms the bind is
    // allowed even then reUseAddress is false so our test uses
    // the platform to determine what the expected result is.
    String platform = System.getProperty("os.name");
    try {
      serverSocket = new ServerSocket();
      serverSocket.setReuseAddress(false);
      serverSocket.bind(theAddress);
      fail("No exception when setReuseAddress is false and we bind:" + theAddress.toString());
    } catch (IOException expected) {
    }
    stillActiveSocket.close();
    theSocket.close();

    // now test case were we set it to true
    anyAddress = new InetSocketAddress(InetAddress.getLocalHost(), 0);
    serverSocket = new ServerSocket();
    serverSocket.setReuseAddress(true);
    serverSocket.bind(anyAddress);
    theAddress = serverSocket.getLocalSocketAddress();

    // make a connection to the server, then close the server
    theSocket = new Socket();
    theSocket.connect(theAddress);
    stillActiveSocket = serverSocket.accept();
    serverSocket.close();

    // now try to rebind the server which should pass with
    // setReuseAddress to true
    try {
      serverSocket = new ServerSocket();
      serverSocket.setReuseAddress(true);
      serverSocket.bind(theAddress);
    } catch (IOException ex) {
      fail(
          "Unexpected exception when setReuseAddress is true and we bind:"
              + theAddress.toString()
              + ":"
              + ex.toString());
    }
    stillActiveSocket.close();
    theSocket.close();

    // now test default case were we expect this to work regardless of
    // the value set
    anyAddress = new InetSocketAddress(InetAddress.getLocalHost(), 0);
    serverSocket = new ServerSocket();
    serverSocket.bind(anyAddress);
    theAddress = serverSocket.getLocalSocketAddress();

    // make a connection to the server, then close the server
    theSocket = new Socket();
    theSocket.connect(theAddress);
    stillActiveSocket = serverSocket.accept();
    serverSocket.close();

    // now try to rebind the server which should pass
    try {
      serverSocket = new ServerSocket();
      serverSocket.bind(theAddress);
    } catch (IOException ex) {
      fail(
          "Unexpected exception when setReuseAddress is the default case and we bind:"
              + theAddress.toString()
              + ":"
              + ex.toString());
    }
    stillActiveSocket.close();
    theSocket.close();
  }
示例#29
0
  /**
   * The main function for processing the incoming datagram.
   *
   * @param dp the datagram.
   */
  private void processIncomingDatagram(DatagramPacket dp) {
    synchronized (sim) {
      SocketAddress sa = dp.getSocketAddress();
      Real2ProxyMsg msg = convertDatagramToReal2ProxyMsg(dp);

      if (Debug.SHOW_PROXY_VEHICLE_DEBUG_MSG) {
        if (Debug.SHOW_PROXY_VEHICLE_PVUPDATE_MSG || !(msg instanceof Real2ProxyPVUpdate)) {
          System.err.printf("Proxy vehicle received a Real2Proxy msg: %s\n", msg);
        }
      }

      if (msg == null) {
        System.err.println("Error: cannot parse the datagram package.");
        return;
      }

      if (sa2ProxyVehicle.containsKey(sa)) {
        // The datagram came from a real vehicle we're already tracking.
        // Simply forward the datagram to the corresponding proxy vehicle
        sa2ProxyVehicle.get(sa).processReal2ProxyMsg(msg);
      } else {
        // We haven't seem this SA before. This must be coming from
        // a new real vehicle that we're not tracking

        // If it is a PV_UPDATE message, instantiate the proxy vehicle and
        // associate the socket address to this proxy vehicle.
        // If not, ignore the message.
        if (msg.messageType == Real2ProxyMsg.Type.PV_UPDATE) {
          Real2ProxyPVUpdate pvUpdateMsg = (Real2ProxyPVUpdate) msg;
          // create a proxy vehicle for this real vehicle
          ProxyVehicleSimView vehicle = makeProxyVehicle(pvUpdateMsg);
          // check the VIN number
          if (VinRegistry.registerVehicleWithExistingVIN(vehicle, pvUpdateMsg.vin)) {
            // update the socket address of the proxy vehicle
            // pull out just the IP <xxx.xxx.xxx.xxx> from the address only
            String address = sa.toString();
            address = address.substring(1, address.indexOf(':'));
            vehicle.setSa(new InetSocketAddress(address, DEFAULT_VEHICLE_UDP_PORT));
            // record the proxy vehicle
            sa2ProxyVehicle.put(sa, vehicle);
            // add the proxy vehicle to the simulator
            sim.addProxyVehicle(vehicle);
            if (Debug.SHOW_PROXY_VEHICLE_DEBUG_MSG) {
              System.err.printf(
                  "A proxy vehicle is created at time %.2f " + "(vin=%d).\n",
                  sim.getSimulationTime(), vehicle.getVIN());
            }
          } else {
            System.err.println(
                "Warning: the VIN of the UPD message has "
                    + "already been used by other vehicles.");
            // don't add the proxy vehicle to the simulator.
          }
        } else {
          // Ignore the message
          if (Debug.SHOW_PROXY_VEHICLE_DEBUG_MSG) {
            System.err.println(
                "Warning: first message from a new real " + "vehicle must be a PVUpdate.");
          }
        }
      }
    }
  }