Handshake() публичный Метод

public Handshake ( string in_header, string &out_header ) : bool
in_header string
out_header string
Результат bool
Пример #1
0
        protected bool doHandshaking(string encryption_type, string encryption_header)
        {
            if (encryption_type == kEncryptionHandshakeBegin)
            {
                // encryption list
                List <EncryptionType> encryption_list = new List <EncryptionType>();

                if (encryption_header.Length > 0)
                {
                    int            begin = 0;
                    int            end   = encryption_header.IndexOf(kDelim2);
                    EncryptionType type;

                    while (end != -1)
                    {
                        type = (EncryptionType)Convert.ToInt32(encryption_header.Substring(begin, end - begin));
                        encryption_list.Add(type);
                        begin = end + 1;
                        end   = encryption_header.IndexOf(kDelim2, begin);
                    }

                    type = (EncryptionType)Convert.ToInt32(encryption_header.Substring(begin));
                    encryption_list.Add(type);
                }

                // Create encryptors
                foreach (EncryptionType type in encryption_list)
                {
                    if (!createEncryptor(type))
                    {
                        return(false);
                    }
                }
            }
            else
            {
                // Encryption handshake message
                EncryptionType type      = (EncryptionType)Convert.ToInt32(encryption_type);
                Encryptor      encryptor = encryptors_[type];
                if (encryptor == null)
                {
                    Log("Unknown encryption: {0}", encryption_type);
                    return(false);
                }

                if (encryptor.state != Encryptor.State.kHandshaking)
                {
                    Log("Unexpected handshake message: {0}", encryptor.name);
                    return(false);
                }

                string out_header = "";
                if (!encryptor.Handshake(encryption_header, ref out_header))
                {
                    Log("Encryption handshake failure: {0}", encryptor.name);
                    return(false);
                }

                FunDebug.Assert(encryptor.state == Encryptor.State.kEstablished);
            }

            bool handshake_complete = true;

            foreach (KeyValuePair <EncryptionType, Encryptor> pair in encryptors_)
            {
                if (pair.Value.state != Encryptor.State.kEstablished)
                {
                    handshake_complete = false;
                    break;
                }
            }

            return(handshake_complete);
        }
Пример #2
0
        protected bool doHandshaking(string encryption_type, string encryption_header)
        {
            if (encryption_type == kEncryptionHandshakeBegin)
            {
                // Creates encryptors
                if (encryption_header.Length > 0)
                {
                    EncryptionType type;
                    int            begin = 0;
                    int            end   = encryption_header.IndexOf(kDelim2);

                    while (end != -1)
                    {
                        type  = (EncryptionType)Convert.ToInt32(encryption_header.Substring(begin, end - begin));
                        begin = end + 1;
                        end   = encryption_header.IndexOf(kDelim2, begin);

                        createEncryptor(type);
                    }

                    type = (EncryptionType)Convert.ToInt32(encryption_header.Substring(begin));
                    createEncryptor(type);
                }
            }
            else
            {
                // Encryption handshake message
                EncryptionType type = (EncryptionType)Convert.ToInt32(encryption_type);
                if (!encryptors_.ContainsKey(type))
                {
                    debug.LogWarning("Encryptor.doHandshaking - Unavailable type: {0}", type);
                    return(false);
                }

                Encryptor encryptor = encryptors_[type];
                if (encryptor.state != Encryptor.State.kHandshaking)
                {
                    debug.LogWarning("Encryptor.doHandshaking - Encryptor state is not handshaking. " +
                                     "state: {0}", encryptor.state);
                    return(false);
                }

                string out_header = "";
                if (!encryptor.Handshake(encryption_header, ref out_header))
                {
                    debug.LogWarning("Encryptor.doHandshaking - Failure in '{0}' Handshake.",
                                     encryptor.name);
                    return(false);
                }

                FunDebug.Assert(encryptor.state == Encryptor.State.kEstablished);
            }

            bool handshake_complete = true;

            foreach (KeyValuePair <EncryptionType, Encryptor> pair in encryptors_)
            {
                if (pair.Value.state != Encryptor.State.kEstablished)
                {
                    handshake_complete = false;
                    break;
                }
            }

            return(handshake_complete);
        }