DtlsHandler implements PacketHandler, DatagramTransport { @Override public boolean canHandle(byte[] packet) { return canHandle(packet, packet.length, 0); } DtlsHandler(DtlsSrtpServerProvider tlsServerProvider); void setChannel(DatagramChannel channel); void addListener(DtlsListener listener); boolean isHandshakeComplete(); boolean isHandshakeFailed(); boolean isHandshaking(); String getLocalFingerprint(); void resetLocalFingerprint(); String getLocalHashFunction(); String getRemoteHashFunction(); String getRemoteFingerprintValue(); String getRemoteFingerprint(); void setRemoteFingerprint(String hashFunction, String fingerprint); PacketTransformer getSrtpDecoder(); PacketTransformer getSrtpEncoder(); PacketTransformer getSrtcpDecoder(); PacketTransformer getSrtcpEncoder(); byte[] decodeRTP(byte[] packet, int offset, int length); byte[] encodeRTP(byte[] packet, int offset, int length); byte[] decodeRTCP(byte[] packet, int offset, int length); byte[] encodeRTCP(byte[] packet, int offset, int length); void handshake(); void reset(); @Override int compareTo(PacketHandler o); @Override boolean canHandle(byte[] packet); @Override boolean canHandle(byte[] packet, int dataLength, int offset); @Override byte[] handle(byte[] packet, InetSocketAddress localPeer, InetSocketAddress remotePeer); @Override byte[] handle(byte[] packet, int dataLength, int offset, InetSocketAddress localPeer, InetSocketAddress remotePeer); @Override int getPipelinePriority(); void setPipelinePriority(int pipelinePriority); @Override int getReceiveLimit(); @Override int getSendLimit(); @Override int receive(byte[] buf, int off, int len, int waitMillis); @Override void send(byte[] buf, int off, int len); @Override void close(); static final int DEFAULT_MTU; final static int MAX_DELAY; }
@Test public void testCanHandle() { DtlsSrtpServerProvider mockedDtlsServerProvider = mock(DtlsSrtpServerProvider.class); DtlsSrtpServer mockedDtlsSrtpServer = mock(DtlsSrtpServer.class); DtlsHandler dtlsHandler = new DtlsHandler(mockedDtlsServerProvider); when(mockedDtlsServerProvider.provide()).thenReturn(mockedDtlsSrtpServer); when(mockedDtlsSrtpServer.getCipherSuites()).thenReturn(cipherSuites); boolean canHandleHelloClient = dtlsHandler.canHandle(HELLO_CLIENT); boolean canHandleRtp = dtlsHandler.canHandle(RTP_PACKET); Assert.assertTrue(canHandleHelloClient); Assert.assertFalse(canHandleRtp); }