public static Channel openChannel ( InetSocketAddress isa ) throws IOException, SocketException { System.err.println("* Opening socket " + isa); Socket s = SocketFactory.getDefault().createSocket(isa.getAddress(), isa.getPort()); s.setKeepAlive(true); s.setTcpNoDelay(true); System.err.println("* Opening channel"); OutputStream outputStream = s.getOutputStream(); DataOutputStream dos = new DataOutputStream(outputStream); dos.writeUTF("Protocol:CLI-connect"); ExecutorService cp = Executors.newCachedThreadPool(new ThreadFactory() { public Thread newThread ( Runnable r ) { Thread t = new Thread(r, "Channel"); t.setDaemon(true); return t; } }); Channel c = new ChannelBuilder("EXPLOIT", cp).withMode(Mode.BINARY).build(s.getInputStream(), outputStream); System.err.println("* Channel open"); return c; } }
return cb.build(proc.getInputStream(),proc.getOutputStream());
"Launch log won't be printed", this); Channel channel = cb.build(commandTransport); setChannel(channel, headerStream, listener);
protected void runCli(Connection c) throws IOException, InterruptedException { ChannelBuilder cb; String name = "CLI channel from " + socket.getInetAddress(); // Connection can contain cipher wrapper, which can't be NIO-ed. // if (hub!=null) // cb = hub.newChannelBuilder(name, Computer.threadPoolForRemoting); // else cb = new ChannelBuilder(name, Computer.threadPoolForRemoting); Channel channel = cb .withMode(Mode.BINARY) .withRestricted(true) .withBaseLoader(Jenkins.getActiveInstance().pluginManager.uberClassLoader) .build(new BufferedInputStream(c.in), new BufferedOutputStream(c.out)); channel.setProperty(CliEntryPoint.class.getName(),new CliManagerImpl(channel)); channel.join(); } }
Channel channel = cb.build(in,out); setChannel(channel,launchLog,listener);
return cb.build(in,out);
public Channel build(SocketChannel socket) throws IOException { this.r = socket; this.w = socket; return super.build(socket); }
/** * {@inheritDoc} */ @Nonnull @Override Channel buildChannel(@Nonnull LegacyJnlpConnectionState state) throws IOException { return state.getChannelBuilder().build(state.getSocket()); }
/** * {@inheritDoc} */ @Nonnull @Override Channel buildChannel(@Nonnull LegacyJnlpConnectionState state) throws IOException { return state.getChannelBuilder().build(state.getSocket()); }
public Channel build(Socket s) throws IOException { // support half-close properly return build(new BufferedInputStream(SocketChannelStream.in(s)), new BufferedOutputStream(SocketChannelStream.out(s))); }
public Channel build(SocketChannel s) throws IOException { return build( SocketChannelStream.in(s), SocketChannelStream.out(s)); }
public Channel build(SelectableChannel r, SelectableChannel w) throws IOException { this.r = r; this.w = w; return super.build( Channels.newInputStream((ReadableByteChannel)r), Channels.newOutputStream((WritableByteChannel)w)); }
protected void runCli(Connection c) throws IOException, InterruptedException { ChannelBuilder cb; String name = "CLI channel from " + socket.getInetAddress(); // Connection can contain cipher wrapper, which can't be NIO-ed. // if (hub!=null) // cb = hub.newChannelBuilder(name, Computer.threadPoolForRemoting); // else cb = new ChannelBuilder(name, Computer.threadPoolForRemoting); Channel channel = cb .withMode(Mode.BINARY) .withRestricted(true) .withBaseLoader(Jenkins.getActiveInstance().pluginManager.uberClassLoader) .build(new BufferedInputStream(c.in), new BufferedOutputStream(c.out)); channel.setProperty(CliEntryPoint.class.getName(),new CliManagerImpl(channel)); channel.join(); } }
/** * {@inheritDoc} */ @Nonnull @Override Channel buildChannel(@Nonnull Jnlp3ConnectionState state) throws IOException { ChannelBuilder channelBuilder = state.getChannelBuilder(); String newCookie = state.getNewCookie(); if (newCookie != null) { channelBuilder.withProperty(COOKIE_NAME, newCookie); } return channelBuilder.build( new CipherInputStream(state.getSocketInputStream(), state.getChannelCiphers().getDecryptCipher()), new CipherOutputStream(state.getSocketOutputStream(), state.getChannelCiphers().getEncryptCipher()) ); }
public void run() { try { Channel south = configureSouth().build(in2,out1); southHandoff.put(south); south.join(); System.out.println("south completed"); } catch (Exception e) { e.printStackTrace(); failure = e; } } };
public static void main(String[] args) throws Exception { final ExecutorService es = Executors.newCachedThreadPool(); Socket s = new Socket("localhost",9953); LOGGER.info("Cnonected"); Channel ch = new ChannelBuilder("client", es) .withHeaderStream(new FlushEveryByteStream(System.out)) .withMode(Mode.BINARY) .build(s); LOGGER.info("Established."); LOGGER.info("Got "+echo(ch,"Hello!")); ch.close(); ch.join(); es.shutdown(); }
private boolean connect() throws IOException { if (conn != null) return false; System.out.println("Requesting jut instance using socket " + socket.getAbsolutePath()); UnixSocketAddress address = new UnixSocketAddress(socket); conn = UnixSocketChannel.open(address); channel = new ChannelBuilder("JenkinsPool", Executors.newCachedThreadPool()) .withMode(Mode.BINARY) .build(ChannelStream.in(conn), ChannelStream.out(conn)); try { controller = (IJenkinsController)channel.waitForRemoteProperty("controller"); controller.start(); url = controller.getUrl(); if (!isQuite) { splitter.addLogListener(getLogPrinter()); } final LogListener l = channel.export(LogListener.class, splitter); channel.call(new InstallLogger(controller,l)); for (byte[] content : toUnpack) { controller.populateJenkinsHome(content, false); } toUnpack.clear(); } catch (InterruptedException e) { throw new IOException(e); } return true; }
/** * Serve individual connection to the test harness. */ private void processConnection(UnixSocketChannel c, JenkinsController j) { try { try { try ( InputStream in = ChannelStream.in(c); OutputStream out = ChannelStream.out(c)) { Channel ch = new ChannelBuilder(j.getLogId(), executors).withMode(Mode.BINARY).build(in, out); ch.setProperty("controller", ch.export(IJenkinsController.class,j)); // wait for the connection to be shut down ch.join(); } } finally { System.out.println("done"); j.stop(); j.tearDown(); c.close(); } } catch (IOException|InterruptedException e) { e.printStackTrace(); } }
/** * Creates a {@link Channel} from the given stream and sets that to this agent. * * @param in * Stream connected to the remote agent. It's the caller's responsibility to do * buffering on this stream, if that's necessary. * @param out * Stream connected to the remote peer. It's the caller's responsibility to do * buffering on this stream, if that's necessary. * @param launchLog * If non-null, receive the portion of data in <tt>is</tt> before * the data goes into the "binary mode". This is useful * when the established communication channel might include some data that might * be useful for debugging/trouble-shooting. * @param listener * Gets a notification when the channel closes, to perform clean up. Can be null. * By the time this method is called, the cause of the termination is reported to the user, * so the implementation of the listener doesn't need to do that again. */ public void setChannel(InputStream in, OutputStream out, OutputStream launchLog, Channel.Listener listener) throws IOException, InterruptedException { ChannelBuilder cb = new ChannelBuilder(nodeName,threadPoolForRemoting) .withMode(Channel.Mode.NEGOTIATE) .withHeaderStream(launchLog); for (ChannelConfigurator cc : ChannelConfigurator.all()) { cc.onChannelBuilding(cb,this); } Channel channel = cb.build(in,out); setChannel(channel,launchLog,listener); }
public Channel start() throws Exception { final FastPipedInputStream in1 = new FastPipedInputStream(); final FastPipedOutputStream out1 = new FastPipedOutputStream(in1); final FastPipedInputStream in2 = new FastPipedInputStream(); final FastPipedOutputStream out2 = new FastPipedOutputStream(in2); final SynchronousQueue<Channel> southHandoff = new SynchronousQueue<Channel>(); executor = Executors.newCachedThreadPool(); Thread t = new Thread("south bridge runner") { public void run() { try { Channel south = configureSouth().build(in2,out1); southHandoff.put(south); south.join(); System.out.println("south completed"); } catch (Exception e) { e.printStackTrace(); failure = e; } } }; t.start(); Channel north = configureNorth().build(in1, out2); south = southHandoff.poll(10, TimeUnit.SECONDS); return north; }