Search in sources :

Example 76 with ByteBuffer

use of streamer.ByteBuffer in project cloudstack by apache.

the class MockSink method handleData.

@Override
public void handleData(ByteBuffer buf, Link link) {
    if (verbose)
        System.out.println("[" + this + "] INFO: Received buf #" + (packetNumber) + " " + buf + ".");
    if (buf == null)
        return;
    if (packetNumber >= bufs.length)
        throw new AssertionError("[" + this + "] Incoming buffer #" + packetNumber + " is not expected. Number of expected buffers: " + bufs.length + ", unexpected buffer: " + buf + ".");
    // Compare incoming buffer with expected buffer
    ByteBuffer expectedBuf = bufs[packetNumber];
    if (!Arrays.equals(expectedBuf.toByteArray(), buf.toByteArray())) {
        dump(buf, expectedBuf);
        throw new AssertionError("[" + this + "] Incoming buffer #" + packetNumber + " is not equal to expected buffer.\n  Actual bufer: " + buf + ",\n  expected buffer: " + expectedBuf + ".");
    }
    // If expected buffer has metadata, then compare it too
    Set<String> metadataKeys = expectedBuf.getMetadataKeys();
    if (metadataKeys.size() > 0) {
        for (String key : metadataKeys) {
            Object expectedValue = expectedBuf.getMetadata(key);
            Object actualValue = buf.getMetadata(key);
            if (actualValue == null)
                throw new AssertionError("[" + this + "] Incoming buffer #" + packetNumber + " is not equal to expected buffer in metadata for key \"" + key + "\".\n  Actual metadata value: " + ",\n  expected value: \"" + expectedValue + "\".");
            if (!expectedValue.equals(actualValue))
                throw new AssertionError("[" + this + "] Incoming buffer #" + packetNumber + " is not equal to expected buffer in metadata for key \"" + key + "\".\n  Actual metadata value: \"" + actualValue + "\",\n  expected value: \"" + expectedValue + "\".");
        }
    }
    if (verbose)
        System.out.println("[" + this + "] INFO: buffers are equal.");
    // Use packetNumber variable to count incoming packets
    packetNumber++;
    buf.unref();
}
Also used : ByteBuffer(streamer.ByteBuffer)

Example 77 with ByteBuffer

use of streamer.ByteBuffer in project cloudstack by apache.

the class MockSource method main.

/**
     * Example.
     */
public static void main(String[] args) {
    Element mockSource = new MockSource("source") {

        {
            bufs = new ByteBuffer[] { new ByteBuffer(new byte[] { 1, 1, 2, 3, 4, 5 }), new ByteBuffer(new byte[] { 2, 1, 2, 3, 4 }), new ByteBuffer(new byte[] { 3, 1, 2, 3 }), new ByteBuffer(new byte[] { 4, 1, 2 }), new ByteBuffer(new byte[] { 5, 1 }) };
            verbose = true;
            delay = 100;
        // this.numBuffers = this.bufs.length;
        }
    };
    Element fakeSink = new FakeSink("sink") {

        {
            verbose = true;
        }
    };
    Link link = new SyncLink();
    mockSource.setLink(STDOUT, link, Direction.OUT);
    fakeSink.setLink(STDIN, link, Direction.IN);
    link.run();
}
Also used : Element(streamer.Element) SyncLink(streamer.SyncLink) ByteBuffer(streamer.ByteBuffer) SyncLink(streamer.SyncLink) Link(streamer.Link)

Example 78 with ByteBuffer

use of streamer.ByteBuffer in project cloudstack by apache.

the class AwtVncKeyboardAdapter method handleData.

@Override
public void handleData(ByteBuffer buf, Link link) {
    if (verbose)
        System.out.println("[" + this + "] INFO: Data received: " + buf + ".");
    KeyOrder order = (KeyOrder) buf.getOrder();
    buf.unref();
    ByteBuffer outBuf = new ByteBuffer(8);
    outBuf.writeByte(RfbConstants.CLIENT_KEYBOARD_EVENT);
    outBuf.writeByte((order.pressed) ? RfbConstants.KEY_DOWN : RfbConstants.KEY_UP);
    // padding
    outBuf.writeShort(0);
    outBuf.writeInt(map_en_us(order));
    pushDataToAllOuts(outBuf);
}
Also used : KeyOrder(common.KeyOrder) ByteBuffer(streamer.ByteBuffer)

Example 79 with ByteBuffer

use of streamer.ByteBuffer in project cloudstack by apache.

the class Vnc33Authentication method main.

/**
     * Example.
     */
public static void main(String[] args) {
    // System.setProperty("streamer.Link.debug", "true");
    System.setProperty("streamer.Element.debug", "true");
    // System.setProperty("streamer.Pipeline.debug", "true");
    final String password = "test";
    Element source = new MockSource("source") {

        {
            bufs = ByteBuffer.convertByteArraysToByteBuffers(// Request authentication and send 16 byte challenge
            new byte[] { 0, 0, 0, RfbConstants.VNC_AUTH, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }, // Respond to challenge with AUTH_OK
            new byte[] { 0, 0, 0, RfbConstants.VNC_AUTH_OK });
        }
    };
    Element mainSink = new FakeSink("mainSink");
    final Vnc33Authentication auth = new Vnc33Authentication("auth", password);
    Element initSink = new MockSink("initSink") {

        {
            // Expect encoded password
            bufs = new ByteBuffer[] { auth.encodePassword(new ByteBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }), password) };
        }
    };
    Pipeline pipeline = new PipelineImpl("test");
    pipeline.addAndLink(source, auth, mainSink);
    pipeline.add(initSink);
    pipeline.link("auth >otout", "initSink");
    pipeline.runMainLoop("source", STDOUT, false, false);
}
Also used : MockSource(streamer.debug.MockSource) FakeSink(streamer.debug.FakeSink) MockSink(streamer.debug.MockSink) PipelineImpl(streamer.PipelineImpl) Element(streamer.Element) ByteBuffer(streamer.ByteBuffer) Pipeline(streamer.Pipeline)

Example 80 with ByteBuffer

use of streamer.ByteBuffer in project cloudstack by apache.

the class Vnc33Hello method handleOneTimeData.

@Override
protected void handleOneTimeData(ByteBuffer buf, Link link) {
    if (verbose)
        System.out.println("[" + this + "] INFO: Data received: " + buf + ".");
    // Initial packet is exactly 12 bytes long
    if (!cap(buf, 12, 12, link, false))
        return;
    // Read protocol version
    String rfbProtocol = new String(buf.data, buf.offset, buf.length, RfbConstants.US_ASCII_CHARSET);
    buf.unref();
    // Server should use RFB protocol 3.x
    if (!rfbProtocol.contains(RfbConstants.RFB_PROTOCOL_VERSION_MAJOR))
        throw new RuntimeException("Cannot handshake with VNC server. Unsupported protocol version: \"" + rfbProtocol + "\".");
    // Send response: we support RFB 3.3 only
    String ourProtocolString = RfbConstants.RFB_PROTOCOL_VERSION + "\n";
    ByteBuffer outBuf = new ByteBuffer(ourProtocolString.getBytes(RfbConstants.US_ASCII_CHARSET));
    if (verbose) {
        outBuf.putMetadata("sender", this);
        outBuf.putMetadata("version", RfbConstants.RFB_PROTOCOL_VERSION);
    }
    pushDataToOTOut(outBuf);
    // Switch off this element from circuit
    switchOff();
}
Also used : ByteBuffer(streamer.ByteBuffer)

Aggregations

ByteBuffer (streamer.ByteBuffer)110 Element (streamer.Element)12 BaseElement (streamer.BaseElement)9 Pipeline (streamer.Pipeline)7 PipelineImpl (streamer.PipelineImpl)7 TSRequest (rdpclient.ntlmssp.asn1.TSRequest)6 MockSink (streamer.debug.MockSink)5 MockSource (streamer.debug.MockSource)5 BitmapRectangle (common.BitmapRectangle)3 ScreenDescription (common.ScreenDescription)3 SyncLink (streamer.SyncLink)3 AssertingByteBuffer (streamer.debug.AssertingByteBuffer)3 BitmapOrder (common.BitmapOrder)2 KeyOrder (common.KeyOrder)2 MouseOrder (common.MouseOrder)2 NegoItem (rdpclient.ntlmssp.asn1.NegoItem)2 Link (streamer.Link)2 FakeSink (streamer.debug.FakeSink)2 BufferedImageCanvas (common.BufferedImageCanvas)1 CopyRectOrder (common.CopyRectOrder)1