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; } }
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(); } }
@CheckForNull Channel.Listener listener) throws IOException, InterruptedException { ChannelBuilder cb = new ChannelBuilder(nodeName,threadPoolForRemoting) .withMode(Channel.Mode.NEGOTIATE) .withHeaderStream(launchLog);
@Override public NioChannelBuilder withMode(Mode mode) { return (NioChannelBuilder)super.withMode(mode); }
/** * {@inheritDoc} */ @Override @Nonnull public ChannelBuilder decorate(@Nonnull ChannelBuilder builder) { if (!client) { builder.withMode(Channel.Mode.NEGOTIATE); } event.fireBeforeChannel(builder); return event.getChannelBuilder(); }
@Override public void beforeChannel(@Nonnull JnlpConnectionState event) { ChannelBuilder bldr = event.getChannelBuilder().withMode(Mode.BINARY); if (jarCache != null) { bldr.withJarCache(jarCache); } }
ExecutorService executor = Executors.newCachedThreadPool(); ChannelBuilder cb = new ChannelBuilder("channel", executor) .withMode(mode) .withJarCacheOrDefault(cache);
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(); } }
/*package*/ Channel(String name, ExecutorService exec, Mode mode, InputStream is, OutputStream os, OutputStream header, boolean restricted, ClassLoader base, Capability capability) throws IOException { this(new ChannelBuilder(name,exec) .withMode(mode) .withBaseLoader(base) .withCapability(capability) .withHeaderStream(header) .withRestricted(restricted), is, os); }
@Override public void beforeChannel(@NonNull JnlpConnectionState event) { event.getChannelBuilder().withMode(mode); }
@Override public void beforeChannel(@NonNull JnlpConnectionState event) { event.getChannelBuilder().withMode(mode); }
try { ChannelBuilder builder = new ChannelBuilder(stack().name(), executorService) .withMode(Channel.Mode.BINARY); if (listener instanceof ChannelDecorator) { channel = decorate(((ChannelDecorator) listener).decorate(builder)).build(transport);
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(); }
protected ChannelBuilder configureSouth() { return new ChannelBuilder("south", executor) .withMode(Mode.BINARY) .withCapability(createCapability()); }
@Test public void exercise() throws Exception { ClassicCommandTransport ct = (ClassicCommandTransport) new ChannelBuilder("dummy",null) .withMode(Mode.BINARY) .withBaseLoader(getClass().getClassLoader()) .negotiate(new ByteArrayInputStream(payload), new NullOutputStream()); verify(ct); }
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; }
protected ChannelBuilder configureNorth() { return new ChannelBuilder("north", executor) .withMode(Mode.BINARY) .withCapability(createCapability()); }
/** * 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); }
/** * This tests the behaviour of the diagnosis blocking on a non-completed stream, as the writer end is kept open. */ @Test(timeout=3000) public void blockingStreamShouldNotPreventDiagnosis() throws Exception { FastPipedInputStream in = new FastPipedInputStream(); FastPipedOutputStream out = new FastPipedOutputStream(in); out.write(payload); ClassicCommandTransport ct = (ClassicCommandTransport) new ChannelBuilder("dummy",null) .withMode(Mode.BINARY) .withBaseLoader(getClass().getClassLoader()) .negotiate(in, new NullOutputStream()); verify(ct); } }