internal IAdminPacketService Create() { IEnumerable <Type> packetTransformerTypes = new AssemblyTypeFinder(Assembly.GetExecutingAssembly(), $"{GetType().Namespace}.PacketTransformers") .WithTypeMatcher(new ClassTypeMatcher()) .WithTypeMatcher(ImplementsTypeMatcher.Create <IPacketTransformer>()) .Find(); IEnumerable <Type> messageTransformerTypes = new AssemblyTypeFinder(Assembly.GetExecutingAssembly(), $"{GetType().Namespace}.MessageTransformers") .WithTypeMatcher(new ClassTypeMatcher()) .WithTypeMatcher(ImplementsTypeMatcher.Create <IMessageTransformer>()) .Find(); IPacketTransformer[] packetTransformers = new IPacketTransformer[packetTransformerTypes.Count()]; IMessageTransformer[] messageTransformers = new IMessageTransformer[messageTransformerTypes.Count()]; for (int i = 0; i < packetTransformers.Length; ++i) { packetTransformers[i] = (IPacketTransformer)Activator.CreateInstance(packetTransformerTypes.ElementAt(i)); } for (int i = 0; i < messageTransformers.Length; ++i) { messageTransformers[i] = (IMessageTransformer)Activator.CreateInstance(messageTransformerTypes.ElementAt(i)); } return(new AdminPacketService(packetTransformers, messageTransformers)); }
public bool DoHandshakeAsClient() { logger.LogDebug("DTLS commencing handshake as client."); if (!handshaking && !handshakeComplete) { this.startTime = DateTime.Now; this.handshaking = true; SecureRandom secureRandom = new SecureRandom(); DtlsClientProtocol clientProtocol = new DtlsClientProtocol(secureRandom); try { var client = (DtlsSrtpClient)connection; // Perform the handshake in a non-blocking fashion Transport = clientProtocol.Connect(client, this); // Prepare the shared key to be used in RTP streaming //client.PrepareSrtpSharedSecret(); // Generate encoders for DTLS traffic if (client.GetSrtpPolicy() != null) { srtpDecoder = GenerateRtpDecoder(); srtpEncoder = GenerateRtpEncoder(); srtcpDecoder = GenerateRtcpDecoder(); srtcpEncoder = GenerateRtcpEncoder(); } // Declare handshake as complete handshakeComplete = true; handshakeFailed = false; handshaking = false; // Warn listeners handshake completed //UnityEngine.Debug.Log("DTLS Handshake Completed"); return(true); } catch (Exception excp) { logger.LogWarning($"DTLS handshake as client failed. {excp.Message}"); // Declare handshake as failed handshakeComplete = false; handshakeFailed = true; handshaking = false; // Warn listeners handshake completed //UnityEngine.Debug.Log("DTLS Handshake failed\n" + e); } } return(false); }
public bool DoHandshakeAsServer() { logger.LogDebug("DTLS commencing handshake as server."); if (!_handshaking && !_handshakeComplete) { this._waitMillis = RetransmissionMilliseconds; this._startTime = System.DateTime.Now; this._handshaking = true; SecureRandom secureRandom = new SecureRandom(); DtlsServerProtocol serverProtocol = new DtlsServerProtocol(secureRandom); try { var server = (DtlsSrtpServer)connection; // Perform the handshake in a non-blocking fashion Transport = serverProtocol.Accept(server, this); // Prepare the shared key to be used in RTP streaming //server.PrepareSrtpSharedSecret(); // Generate encoders for DTLS traffic if (server.GetSrtpPolicy() != null) { srtpDecoder = GenerateRtpDecoder(); srtpEncoder = GenerateRtpEncoder(); srtcpDecoder = GenerateRtcpDecoder(); srtcpEncoder = GenerateRtcpEncoder(); } // Declare handshake as complete _handshakeComplete = true; _handshakeFailed = false; _handshaking = false; // Warn listeners handshake completed //UnityEngine.Debug.Log("DTLS Handshake Completed"); return(true); } catch (System.Exception excp) { logger.LogWarning($"DTLS handshake as server failed. {excp.Message}"); // Declare handshake as failed _handshakeComplete = false; _handshakeFailed = true; _handshaking = false; // Warn listeners handshake completed //UnityEngine.Debug.Log("DTLS Handshake failed\n"+ e); } } return(false); }
private bool DoHandshakeAsServer(out string handshakeError) { handshakeError = null; logger.LogDebug("DTLS commencing handshake as server."); if (!_handshaking && !_handshakeComplete) { this._waitMillis = RetransmissionMilliseconds; this._startTime = System.DateTime.Now; this._handshaking = true; SecureRandom secureRandom = new SecureRandom(); DtlsServerProtocol serverProtocol = new DtlsServerProtocol(secureRandom); try { var server = (DtlsSrtpServer)connection; // Perform the handshake in a non-blocking fashion Transport = serverProtocol.Accept(server, this); // Prepare the shared key to be used in RTP streaming //server.PrepareSrtpSharedSecret(); // Generate encoders for DTLS traffic if (server.GetSrtpPolicy() != null) { srtpDecoder = GenerateRtpDecoder(); srtpEncoder = GenerateRtpEncoder(); srtcpDecoder = GenerateRtcpDecoder(); srtcpEncoder = GenerateRtcpEncoder(); } // Declare handshake as complete _handshakeComplete = true; _handshakeFailed = false; _handshaking = false; // Warn listeners handshake completed //UnityEngine.Debug.Log("DTLS Handshake Completed"); return(true); } catch (System.Exception excp) { if (excp.InnerException is TimeoutException) { logger.LogWarning(excp, $"DTLS handshake as server timed out waiting for handshake to complete."); handshakeError = "timeout"; } else { handshakeError = "unknown"; if (excp is Org.BouncyCastle.Crypto.Tls.TlsFatalAlert) { handshakeError = (excp as Org.BouncyCastle.Crypto.Tls.TlsFatalAlert).Message; } logger.LogWarning(excp, $"DTLS handshake as server failed. {excp.Message}"); } // Declare handshake as failed _handshakeComplete = false; _handshakeFailed = true; _handshaking = false; // Warn listeners handshake completed //UnityEngine.Debug.Log("DTLS Handshake failed\n"+ e); } } return(false); }