예제 #1
0
 public void WriteTo(BinaryWriter bW)
 {
     bW.Write((byte)1); //version
     _userId.WriteTo(bW.BaseStream);
     bW.Write((byte)_status);
     bW.Write(_deliveredOn);
 }
예제 #2
0
        public override void WriteTo(Stream s)
        {
            base.WriteTo(s);

            _nonce.WriteTo(s);
            s.WriteByte((byte)_cryptoOptions);
        }
예제 #3
0
        public override void WriteTo(Stream s)
        {
            base.WriteTo(s);

            s.Write(BitConverter.GetBytes(Convert.ToUInt16(_ephemeralPublicKey.Length)), 0, 2);
            s.Write(_ephemeralPublicKey, 0, _ephemeralPublicKey.Length);

            _pskAuth.WriteTo(s);
        }
예제 #4
0
        public override void WriteTo(Stream s)
        {
            base.WriteTo(s);

            s.WriteByte(_version);
            _nonce.WriteTo(s);
            s.WriteByte((byte)_supportedCiphers);
            s.WriteByte((byte)_options);
        }
예제 #5
0
        public static byte[] CreateFileUnparticipate(BinaryNumber fileID)
        {
            using (MemoryStream mS = new MemoryStream(fileID.Number.Length + 1 + 1))
            {
                mS.WriteByte((byte)BitChatMessageType.FileShareUnparticipate); //1 byte
                fileID.WriteTo(mS);

                return(mS.ToArray());
            }
        }
예제 #6
0
        public static byte[] CreateFileBlockAvailable(BinaryNumber fileID, int blockNumber)
        {
            using (MemoryStream mS = new MemoryStream(fileID.Number.Length + 1 + 1 + 4))
            {
                mS.WriteByte((byte)BitChatMessageType.FileBlockAvailable); //1 byte
                fileID.WriteTo(mS);
                mS.Write(BitConverter.GetBytes(blockNumber), 0, 4);        //4 bytes

                return(mS.ToArray());
            }
        }
예제 #7
0
        public static byte[] CreateFileBlockRequest(BinaryNumber fileID, int blockNumber, ushort dataPort)
        {
            using (MemoryStream mS = new MemoryStream(fileID.Number.Length + 1 + 1 + 4 + 2))
            {
                mS.WriteByte((byte)BitChatMessageType.FileBlockRequest); //1 byte
                fileID.WriteTo(mS);
                mS.Write(BitConverter.GetBytes(blockNumber), 0, 4);      //4 bytes
                mS.Write(BitConverter.GetBytes(dataPort), 0, 2);         //2 bytes

                return(mS.ToArray());
            }
        }
예제 #8
0
        public override void WriteTo(Stream s)
        {
            base.WriteTo(s);

            _userId.WriteTo(s);

            s.Write(BitConverter.GetBytes(Convert.ToUInt16(_publicKey.Length)), 0, 2);
            s.Write(_publicKey, 0, _publicKey.Length);

            s.Write(BitConverter.GetBytes(Convert.ToUInt16(_signature.Length)), 0, 2);
            s.Write(_signature, 0, _signature.Length);
        }
예제 #9
0
        public void WriteTo(BinaryWriter bW)
        {
            _peerUserId.WriteTo(bW.BaseStream);

            if (_peerName == null)
            {
                bW.Write((byte)0);
            }
            else
            {
                bW.WriteShortString(_peerName);
            }

            bW.Write(Convert.ToByte(_peerEPs.Length));

            foreach (EndPoint peerEP in _peerEPs)
            {
                peerEP.WriteTo(bW);
            }
        }
예제 #10
0
        internal void WriteTo(BinaryWriter bW)
        {
            bW.Write((byte)1); //version

            bW.Write(_remoteMessageNumber);
            bW.Write(_messageDate);

            if (_senderUserId == null)
            {
                bW.Write((byte)0);
            }
            else
            {
                _senderUserId.WriteTo(bW.BaseStream);
            }

            if (_recipients == null)
            {
                bW.Write((byte)0);
            }
            else
            {
                bW.Write(Convert.ToByte(_recipients.Length));
                foreach (MessageRecipient recipient in _recipients)
                {
                    recipient.WriteTo(bW);
                }
            }

            WriteTransmittedMessageDataTo(bW);

            if (_filePath == null)
            {
                bW.Write((byte)0);
            }
            else
            {
                bW.WriteShortString(_filePath);
            }
        }
예제 #11
0
        public void WriteTo(BinaryWriter bW)
        {
            bW.Write((byte)1);         //version
            _sourceNodeEP.WriteTo(bW); //source node EP
            bW.Write((byte)_type);     //type

            switch (_type)
            {
            case DhtRpcType.FIND_NODE:
                _networkId.WriteTo(bW.BaseStream);

                if (_contacts == null)
                {
                    bW.Write((byte)0);
                }
                else
                {
                    bW.Write(Convert.ToByte(_contacts.Length));
                    foreach (NodeContact contact in _contacts)
                    {
                        contact.WriteTo(bW);
                    }
                }

                break;

            case DhtRpcType.FIND_PEERS:
                _networkId.WriteTo(bW.BaseStream);

                if (_contacts == null)
                {
                    bW.Write((byte)0);
                }
                else
                {
                    bW.Write(Convert.ToByte(_contacts.Length));
                    foreach (NodeContact contact in _contacts)
                    {
                        contact.WriteTo(bW);
                    }
                }

                if (_peers == null)
                {
                    bW.Write((byte)0);
                }
                else
                {
                    bW.Write(Convert.ToByte(_peers.Length));
                    foreach (EndPoint peer in _peers)
                    {
                        peer.WriteTo(bW);
                    }
                }
                break;

            case DhtRpcType.ANNOUNCE_PEER:
                _networkId.WriteTo(bW.BaseStream);

                if (_peers == null)
                {
                    bW.Write((byte)0);
                }
                else
                {
                    bW.Write(Convert.ToByte(_peers.Length));
                    foreach (EndPoint peer in _peers)
                    {
                        peer.WriteTo(bW);
                    }
                }
                break;
            }
        }
예제 #12
0
        public void WriteTo(BinaryWriter bW)
        {
            bW.Write((byte)1); //version

            //
            bW.Write((byte)_type);
            bW.WriteBuffer(_privateKey);
            bW.Write((byte)_supportedCiphers);

            //
            _userId.WriteTo(bW.BaseStream);

            //
            bW.Write(_localServicePort);
            bW.WriteShortString(_downloadFolder);

            //
            bW.Write(_profileDateModified);
            bW.WriteShortString(_profileDisplayName);
            bW.Write((byte)_profileStatus);
            bW.WriteShortString(_profileStatusMessage);

            //
            bW.Write(_profileImageDateModified);
            bW.WriteBuffer(_profileDisplayImage);

            //
            _ipv4BootstrapDhtNodes = _connectionManager.DhtManager.GetIPv4DhtNodes();
            bW.Write(_ipv4BootstrapDhtNodes.Length);
            foreach (EndPoint ep in _ipv4BootstrapDhtNodes)
            {
                ep.WriteTo(bW);
            }

            _ipv6BootstrapDhtNodes = _connectionManager.DhtManager.GetIPv6DhtNodes();
            bW.Write(_ipv6BootstrapDhtNodes.Length);
            foreach (EndPoint ep in _ipv6BootstrapDhtNodes)
            {
                ep.WriteTo(bW);
            }

            _torBootstrapDhtNodes = _connectionManager.DhtManager.GetTorDhtNodes();
            bW.Write(_torBootstrapDhtNodes.Length);
            foreach (EndPoint ep in _torBootstrapDhtNodes)
            {
                ep.WriteTo(bW);
            }

            //
            bW.Write(_enableUPnP);
            bW.Write(_allowInboundInvitations);
            bW.Write(_allowOnlyLocalInboundInvitations);

            //
            if (_proxy == null)
            {
                bW.Write(false);
            }
            else
            {
                bW.Write(true);
                bW.Write((byte)_proxy.Type);
                bW.WriteShortString(_proxy.Address);
                bW.Write(_proxy.Port);

                if (_proxy.Credential == null)
                {
                    bW.Write(false);
                }
                else
                {
                    bW.Write(true);
                    bW.WriteShortString(_proxy.Credential.UserName);
                    bW.WriteShortString(_proxy.Credential.Password);
                }
            }

            //
            bW.WriteBuffer(_appData);

            //
            lock (_networks)
            {
                bW.Write(_networks.Count);

                foreach (KeyValuePair <BinaryNumber, MeshNetwork> network in _networks)
                {
                    network.Value.WriteTo(bW);
                }
            }
        }
예제 #13
0
        public override void WriteTo(Stream s)
        {
            base.WriteTo(s);

            _hmac.WriteTo(s);
        }