public bool DoHandshake(out string handshakeError)
 {
     if (connection.IsClient())
     {
         return(DoHandshakeAsClient(out handshakeError));
     }
     else
     {
         return(DoHandshakeAsServer(out handshakeError));
     }
 }
 public bool DoHandshake()
 {
     if (connection.IsClient())
     {
         return(DoHandshakeAsClient());
     }
     else
     {
         return(DoHandshakeAsServer());
     }
 }
Example #3
0
        public int Receive(byte[] buf, int off, int len, int waitMillis)
        {
            if (!handshakeComplete)
            {
                // The timeout for the handshake applies from when it started rather than
                // for each individual receive..
                int millisecondsRemaining = GetMillisecondsRemaining();

                //Handshake reliable contains too long default backoff times
                waitMillis = Math.Max(100, waitMillis / (random.Next(100, 1000)));

                if (millisecondsRemaining <= 0)
                {
                    logger.LogWarning(
                        $"DTLS transport timed out after {TimeoutMilliseconds}ms waiting for handshake from remote {(connection.IsClient() ? "server" : "client")}.");
                    throw new TimeoutException();
                }
                else if (!_isClosed)
                {
                    waitMillis = (int)Math.Min(waitMillis, millisecondsRemaining);
                    return(Read(buf, off, len, waitMillis));
                }
                else
                {
                    return(DTLS_RECEIVE_ERROR_CODE);
                }
            }
            else if (!_isClosed)
            {
                return(Read(buf, off, len, waitMillis));
            }
            else
            {
                return(DTLS_RECEIVE_ERROR_CODE);
            }
        }