示例#1
0
        public override byte[] Encode(G2Protocol protocol)
        {
            lock (protocol.WriteSection)
            {
                G2Frame folder = protocol.WritePacket(null, StoragePacket.Folder, null);

                protocol.WritePacket(folder, Packet_UID, BitConverter.GetBytes(UID));
                protocol.WritePacket(folder, Packet_ParentUID, BitConverter.GetBytes(ParentUID));
                protocol.WritePacket(folder, Packet_Name, UTF8Encoding.UTF8.GetBytes(Name));
                protocol.WritePacket(folder, Packet_Date, BitConverter.GetBytes(Date.ToBinary()));

                StorageFlags netFlags = Flags & ~(StorageFlags.Modified | StorageFlags.Unlocked);
                protocol.WritePacket(folder, Packet_Flags, BitConverter.GetBytes((ushort)netFlags));

                if (Note != null)
                {
                    protocol.WritePacket(folder, Packet_Note, UTF8Encoding.UTF8.GetBytes(Note));
                }

                protocol.WritePacket(folder, Packet_Revs, BitConverter.GetBytes(Revs));
                protocol.WritePacket(folder, Packet_Integrated, BitConverter.GetBytes(IntegratedID));

                byte[] scopefield = new byte[10];
                foreach (ulong id in Scope.Keys)
                {
                    BitConverter.GetBytes(id).CopyTo(scopefield, 0);
                    BitConverter.GetBytes(Scope[id]).CopyTo(scopefield, 8);

                    protocol.WritePacket(folder, Packet_Scope, scopefield);
                }

                return(protocol.WriteFinish());
            }
        }
示例#2
0
        public override byte[] Encode(G2Protocol protocol)
        {
            lock (protocol.WriteSection)
            {
                G2Frame ack = protocol.WritePacket(null, TransferPacket.Ack, null);

                protocol.WritePacket(ack, Packet_FileID, BitConverter.GetBytes(FileID));
                protocol.WritePacket(ack, Packet_StartByte, CompactNum.GetBytes(StartByte));

                if (Uninitialized)
                {
                    protocol.WritePacket(ack, Packet_Uninitialized, null);
                }

                if (Error)
                {
                    protocol.WritePacket(ack, Packet_Error, null);
                }

                if (Bitfield != null)
                {
                    protocol.WritePacket(ack, Packet_Bitfield, Bitfield);
                }

                return(protocol.WriteFinish());
            }
        }
示例#3
0
        public override byte[] Encode(G2Protocol protocol)
        {
            lock (protocol.WriteSection)
            {
                G2Frame bdy = protocol.WritePacket(null, RootPacket.Comm, Payload);

                protocol.WritePacket(bdy, Packet_SenderDht, BitConverter.GetBytes(SenderID));
                protocol.WritePacket(bdy, Packet_SenderClient, BitConverter.GetBytes(SenderClient));
                protocol.WritePacket(bdy, Packet_TargetDht, BitConverter.GetBytes(TargetID));
                protocol.WritePacket(bdy, Packet_TargetClient, BitConverter.GetBytes(TargetClient));
                protocol.WritePacket(bdy, Packet_Type, BitConverter.GetBytes(PacketType));
                protocol.WritePacket(bdy, Packet_ID, BitConverter.GetBytes(PeerID));
                protocol.WritePacket(bdy, Packet_Seq, BitConverter.GetBytes(Sequence));

                if (Ident != 0)
                {
                    protocol.WritePacket(bdy, Packet_Ident, BitConverter.GetBytes(Ident));
                }

                if (ToAddress != null)
                {
                    ToAddress.WritePacket(protocol, bdy, Packet_To);
                }
                if (RemoteProxy != null)
                {
                    RemoteProxy.WritePacket(protocol, bdy, Packet_Proxy);
                }

                return(protocol.WriteFinish());
            }
        }
示例#4
0
        public override byte[] Encode(G2Protocol protocol)
        {
            byte[] details = Details.Encode(protocol); // prevent protocol conflict

            lock (protocol.WriteSection)
            {
                G2Frame ping = protocol.WritePacket(null, TransferPacket.Ping, null);

                protocol.WritePacket(ping, Packet_Target, BitConverter.GetBytes(Target));
                protocol.WritePacket(ping, Packet_Details, details);
                protocol.WritePacket(ping, Packet_Status, BitConverter.GetBytes((int)Status));

                if (MissingDepth >= 0)
                {
                    protocol.WritePacket(ping, Packet_MissingDepth, CompactNum.GetBytes(MissingDepth));
                }

                if (RequestInfo)
                {
                    protocol.WritePacket(ping, Packet_RequestInfo, null);
                }

                if (RequestAlts)
                {
                    protocol.WritePacket(ping, Packet_RequestAlts, null);
                }

                if (BitfieldUpdated)
                {
                    protocol.WritePacket(ping, Packet_BitfieldUpdated, null);
                }

                return(protocol.WriteFinish());
            }
        }
示例#5
0
        public override byte[] Encode(G2Protocol protocol)
        {
            lock (protocol.WriteSection)
            {
                G2Frame po = protocol.WritePacket(null, NetworkPacket.Pong, null);

                if (Source != null)
                {
                    Source.WritePacket(protocol, po, Packet_Source);
                }

                if (RemoteIP != null)
                {
                    protocol.WritePacket(po, Packet_RemoteIP, RemoteIP.GetAddressBytes());
                }

                if (Direct)
                {
                    protocol.WritePacket(po, Packet_Direct, null);
                }

                if (Version != 0)
                {
                    protocol.WritePacket(po, Packet_Version, CompactNum.GetBytes(Version));
                }


                // network packet
                InternalData = protocol.WriteFinish();

                return(base.Encode(protocol));
            }
        }
示例#6
0
        public override byte[] Encode(G2Protocol protocol)
        {
            lock (protocol.WriteSection)
            {
                G2Frame ack = protocol.WritePacket(null, NetworkPacket.SearchAck, null);

                Source.WritePacket(protocol, ack, Packet_Source);

                protocol.WritePacket(ack, Packet_SearchID, BitConverter.GetBytes(SearchID));
                protocol.WritePacket(ack, Packet_Service, CompactNum.GetBytes(Service));

                if (Proxied)
                {
                    protocol.WritePacket(ack, Packet_Proxied, null);
                }

                foreach (DhtContact contact in ContactList)
                {
                    contact.WritePacket(protocol, ack, Packet_Contacts);
                }

                foreach (byte[] value in ValueList)
                {
                    protocol.WritePacket(ack, Packet_Values, value);
                }

                InternalData = protocol.WriteFinish();

                return(base.Encode(protocol));
            }
        }
示例#7
0
        public override byte[] Encode(G2Protocol protocol)
        {
            lock (protocol.WriteSection)
            {
                G2Frame goal = protocol.WritePacket(null, PlanPacket.Goal, null);

                protocol.WritePacket(goal, Packet_Ident, BitConverter.GetBytes(Ident));
                protocol.WritePacket(goal, Packet_Project, BitConverter.GetBytes(Project));

                protocol.WritePacket(goal, Packet_BranchUp, BitConverter.GetBytes(BranchUp));
                protocol.WritePacket(goal, Packet_BranchDown, BitConverter.GetBytes(BranchDown));

                protocol.WritePacket(goal, Packet_Title, UTF8Encoding.UTF8.GetBytes(Title));
                protocol.WritePacket(goal, Packet_End, BitConverter.GetBytes(End.ToBinary()));
                protocol.WritePacket(goal, Packet_Desc, UTF8Encoding.UTF8.GetBytes(Description));

                protocol.WritePacket(goal, Packet_Person, BitConverter.GetBytes(Person));

                protocol.WritePacket(goal, Packet_Archived, BitConverter.GetBytes(Archived));

                protocol.WritePacket(goal, Packet_EstCompleted, BitConverter.GetBytes(EstCompleted));
                protocol.WritePacket(goal, Packet_EstTotal, BitConverter.GetBytes(EstTotal));

                return(protocol.WriteFinish());
            }
        }
示例#8
0
        public override byte[] Encode(G2Protocol protocol)
        {
            lock (protocol.WriteSection)
            {
                G2Frame pong = protocol.WritePacket(null, TransferPacket.Pong, null);

                protocol.WritePacket(pong, Packet_FileID, BitConverter.GetBytes(FileID));
                protocol.WritePacket(pong, Packet_Timeout, CompactNum.GetBytes(Timeout));
                protocol.WritePacket(pong, Packet_Status, CompactNum.GetBytes((int)Status));

                if (Error)
                {
                    protocol.WritePacket(pong, Packet_Error, null);
                }

                if (InternalSize != 0)
                {
                    protocol.WritePacket(pong, Packet_InternalSize, CompactNum.GetBytes(InternalSize));
                    protocol.WritePacket(pong, Packet_ChunkSize, CompactNum.GetBytes(ChunkSize));
                    protocol.WritePacket(pong, Packet_BitCount, CompactNum.GetBytes(BitCount));
                }

                foreach (DhtClient client in Alts.Keys)
                {
                    G2Frame alt = protocol.WritePacket(pong, Packet_AltClient, client.ToBytes());

                    foreach (DhtAddress address in Alts[client])
                    {
                        address.WritePacket(protocol, alt, Packet_AltAddress);
                    }
                }

                return(protocol.WriteFinish());
            }
        }
示例#9
0
        // cant write local info (read) because post is re-transmitted

        public override byte[] Encode(G2Protocol protocol)
        {
            lock (protocol.WriteSection)
            {
                G2Frame header = protocol.WritePacket(null, BoardPacket.PostHeader, null);

                protocol.WritePacket(header, Packet_Source, Source);
                protocol.WritePacket(header, Packet_Target, Target);

                protocol.WritePacket(header, Packet_ProjectID, BitConverter.GetBytes(ProjectID));
                protocol.WritePacket(header, Packet_PostID, BitConverter.GetBytes(PostID));
                protocol.WritePacket(header, Packet_ParentID, BitConverter.GetBytes(ParentID));
                protocol.WritePacket(header, Packet_Time, BitConverter.GetBytes(Time.ToBinary()));
                protocol.WritePacket(header, Packet_Scope, new byte[] { (byte)Scope });

                protocol.WritePacket(header, Packet_Version, BitConverter.GetBytes(Version));
                protocol.WritePacket(header, Packet_EditTime, BitConverter.GetBytes(EditTime.ToBinary()));
                protocol.WritePacket(header, Packet_Archived, BitConverter.GetBytes(Archived));

                protocol.WritePacket(header, Packet_FileKey, FileKey);
                protocol.WritePacket(header, Packet_FileHash, FileHash);
                protocol.WritePacket(header, Packet_FileSize, BitConverter.GetBytes(FileSize));
                protocol.WritePacket(header, Packet_FileStart, BitConverter.GetBytes(FileStart));

                return(protocol.WriteFinish());
            }
        }
示例#10
0
        public override byte[] Encode(G2Protocol protocol)
        {
            lock (protocol.WriteSection)
            {
                G2Frame invite = protocol.WritePacket(null, ChatPacket.Invite, null);

                protocol.WritePacket(invite, Packet_RoomID, BitConverter.GetBytes(RoomID));

                if (Host != null)
                {
                    protocol.WritePacket(invite, Packet_Host, Host);
                }

                if (SignedInvite != null)
                {
                    protocol.WritePacket(invite, Packet_SignedInvite, SignedInvite);
                }

                if (Title.Length > 0)
                {
                    protocol.WritePacket(invite, Packet_Title, UTF8Encoding.UTF8.GetBytes(Title));
                }

                return(protocol.WriteFinish());
            }
        }
示例#11
0
        public override byte[] Encode(G2Protocol protocol)
        {
            lock (protocol.WriteSection)
            {
                G2Frame root = protocol.WritePacket(null, SharePacket.File, null);

                protocol.WritePacket(root, Packet_Name, UTF8Encoding.UTF8.GetBytes(Name));
                protocol.WritePacket(root, Packet_Hash, Hash);
                protocol.WritePacket(root, Packet_Size, CompactNum.GetBytes(Size));
                protocol.WritePacket(root, Packet_FileKey, FileKey);

                if (SaveLocal)
                {
                    if (SystemPath != null)
                    {
                        protocol.WritePacket(root, Packet_SystemPath, UTF8Encoding.UTF8.GetBytes(SystemPath));
                    }

                    if (Public)
                    {
                        protocol.WritePacket(root, Packet_Public, null);
                    }
                }

                return(protocol.WriteFinish());
            }
        }
示例#12
0
        public override byte[] Encode(G2Protocol protocol)
        {
            lock (protocol.WriteSection)
            {
                G2Frame bye = protocol.WritePacket(null, NetworkPacket.Bye, null);

                protocol.WritePacket(bye, Packet_Source, BitConverter.GetBytes(SenderID));

                foreach (DhtContact contact in ContactList)
                {
                    contact.WritePacket(protocol, bye, Packet_Contacts);
                }

                if (Message != null)
                {
                    protocol.WritePacket(bye, Packet_Message, UTF8Encoding.UTF8.GetBytes(Message));
                }

                if (Reconnect)
                {
                    protocol.WritePacket(bye, Packet_Reconnect, null);
                }

                // network packet
                InternalData = protocol.WriteFinish();

                return(base.Encode(protocol));
            }
        }
示例#13
0
        public byte[] Encode(G2Protocol protocol, bool local)
        {
            lock (protocol.WriteSection)
            {
                G2Frame header = protocol.WritePacket(null, MailPacket.MailHeader, null);

                protocol.WritePacket(header, Packet_Source, Source);
                protocol.WritePacket(header, Packet_Target, Target);
                protocol.WritePacket(header, Packet_FileKey, FileKey);
                protocol.WritePacket(header, Packet_FileHash, FileHash);
                protocol.WritePacket(header, Packet_FileSize, BitConverter.GetBytes(FileSize));
                protocol.WritePacket(header, Packet_SourceVersion, BitConverter.GetBytes(SourceVersion));
                protocol.WritePacket(header, Packet_TargetVersion, BitConverter.GetBytes(TargetVersion));
                protocol.WritePacket(header, Packet_MailID, MailID);
                protocol.WritePacket(header, Packet_ThreadID, BitConverter.GetBytes(ThreadID));

                if (local)
                {
                    protocol.WritePacket(header, Packet_LocalKey, LocalKey);
                    protocol.WritePacket(header, Packet_FileStart, BitConverter.GetBytes(FileStart));
                    protocol.WritePacket(header, Packet_Read, BitConverter.GetBytes(Read));
                    protocol.WritePacket(header, Packet_Received, BitConverter.GetBytes(Received.ToBinary()));
                }

                return(protocol.WriteFinish());
            }
        }
示例#14
0
        public byte[] EncodeLight(G2Protocol protocol)
        {
            lock (protocol.WriteSection)
            {
                G2Frame loc = protocol.WritePacket(null, LocationPacket.Data, null);

                Source.WritePacket(protocol, loc, Packet_Source);
                protocol.WritePacket(loc, Packet_IP, IP.GetAddressBytes());

                foreach (DhtAddress proxy in Proxies)
                {
                    proxy.WritePacket(protocol, loc, Packet_Proxies);
                }

                if (TunnelClient != null)
                {
                    protocol.WritePacket(loc, Packet_TunnelClient, TunnelClient.ToBytes());
                }

                foreach (DhtAddress server in TunnelServers)
                {
                    server.WritePacket(protocol, loc, Packet_TunnelServers);
                }

                return(protocol.WriteFinish());
            }
        }
示例#15
0
        public override byte[] Encode(G2Protocol protocol)
        {
            lock (protocol.WriteSection)
            {
                G2Frame ack = protocol.WritePacket(null, NetworkPacket.CrawlAck, null);

                Source.WritePacket(protocol, ack, Packet_Source);
                protocol.WritePacket(ack, Packet_Version, UTF8Encoding.UTF8.GetBytes(Version));
                protocol.WritePacket(ack, Packet_Uptime, BitConverter.GetBytes(Uptime));

                foreach (DhtContact proxy in ProxyServers)
                {
                    proxy.WritePacket(protocol, ack, Packet_ProxyServers);
                }

                foreach (DhtContact proxy in ProxyClients)
                {
                    proxy.WritePacket(protocol, ack, Packet_ProxyClients);
                }

                // network packet
                InternalData = protocol.WriteFinish();

                return(base.Encode(protocol));
            }
        }
示例#16
0
 internal override byte[] Encode(G2Protocol protocol)
 {
     lock (protocol.WriteSection)
     {
         G2Frame root = protocol.WritePacket(null, SharingPacket.PublicRequest, null);
         return protocol.WriteFinish();
     }
 }
示例#17
0
 public override byte[] Encode(G2Protocol protocol)
 {
     lock (protocol.WriteSection)
     {
         G2Frame root = protocol.WritePacket(null, SharePacket.PublicRequest, null);
         return(protocol.WriteFinish());
     }
 }
示例#18
0
 public override byte[] Encode(G2Protocol protocol)
 {
     lock (protocol.WriteSection)
     {
         protocol.WritePacket(null, RootPacket.Padding, Filler);
         return(protocol.WriteFinish());
     }
 }
示例#19
0
文件: IMPackets.cs 项目: nandub/DeOps
        public override byte[] Encode(G2Protocol protocol)
        {
            lock (protocol.WriteSection)
            {
                protocol.WritePacket(null, IMPacket.Alive, null);

                return(protocol.WriteFinish());
            }
        }
示例#20
0
文件: DhtBucket.cs 项目: nandub/DeOps
        public byte[] Encode(G2Protocol protocol, byte name)
        {
            lock (protocol.WriteSection)
            {
                WritePacket(protocol, null, name);

                return(protocol.WriteFinish());
            }
        }
示例#21
0
        public override byte[] Encode(G2Protocol protocol)
        {
            lock (protocol.WriteSection)
            {
                G2Frame close = protocol.WritePacket(null, CommPacket.Close, null);

                protocol.WritePacket(close, Packet_Message, UTF8Encoding.UTF8.GetBytes(Reason));

                return(protocol.WriteFinish());
            }
        }
示例#22
0
        public override byte[] Encode(G2Protocol protocol)
        {
            lock (protocol.WriteSection)
            {
                G2Frame root = protocol.WritePacket(null, StoragePacket.Root, null);

                protocol.WritePacket(root, Packet_Project, BitConverter.GetBytes(ProjectID));

                return(protocol.WriteFinish());
            }
        }
示例#23
0
        public override byte[] Encode(G2Protocol protocol)
        {
            lock (protocol.WriteSection)
            {
                G2Frame ka = protocol.WritePacket(null, CommPacket.KeyAck, null);

                protocol.WritePacket(ka, Packet_Key, PublicKey);

                return(protocol.WriteFinish());
            }
        }
示例#24
0
        public override byte[] Encode(G2Protocol protocol)
        {
            lock (protocol.WriteSection)
            {
                G2Frame update = protocol.WritePacket(null, CommPacket.ProxyUpdate, null);

                Proxy.WritePacket(protocol, update, Packet_Proxy);

                return(protocol.WriteFinish());
            }
        }
示例#25
0
        public override byte[] Encode(G2Protocol protocol)
        {
            lock (protocol.WriteSection)
            {
                G2Frame sr = protocol.WritePacket(null, CommPacket.SessionRequest, null);

                protocol.WritePacket(sr, Packet_Key, EncryptedKey);

                return(protocol.WriteFinish());
            }
        }
示例#26
0
        public override byte[] Encode(G2Protocol protocol)
        {
            lock (protocol.WriteSection)
            {
                G2Frame sa = protocol.WritePacket(null, CommPacket.SessionAck, null);

                protocol.WritePacket(sa, Packet_Name, UTF8Encoding.UTF8.GetBytes(Name));

                return(protocol.WriteFinish());
            }
        }
示例#27
0
        public override byte[] Encode(G2Protocol protocol)
        {
            lock (protocol.WriteSection)
            {
                G2Frame ping = protocol.WritePacket(null, LocationPacket.Ping, null);

                protocol.WritePacket(ping, Packet_RemoteVersion, CompactNum.GetBytes(RemoteVersion));

                return(protocol.WriteFinish());
            }
        }
示例#28
0
        public override byte[] Encode(G2Protocol protocol)
        {
            lock (protocol.WriteSection)
            {
                G2Frame packet = protocol.WritePacket(null, VoicePacket.Audio, Audio);

                protocol.WritePacket(packet, Packet_FrameSize, CompactNum.GetBytes(FrameSize));

                return(protocol.WriteFinish());
            }
        }
示例#29
0
文件: OpUser.cs 项目: nandub/DeOps
        public override byte[] Encode(G2Protocol protocol)
        {
            lock (protocol.WriteSection)
            {
                G2Frame user = protocol.WritePacket(null, IdentityPacket.UserInfo, Key);

                protocol.WritePacket(user, Packet_Name, UTF8Encoding.UTF8.GetBytes(Name));

                return(protocol.WriteFinish());
            }
        }
示例#30
0
        public override byte[] Encode(G2Protocol protocol)
        {
            lock (protocol.WriteSection)
            {
                G2Frame file = protocol.WritePacket(null, BoardPacket.PostFile, null);

                protocol.WritePacket(file, Packet_Name, UTF8Encoding.UTF8.GetBytes(Name));
                protocol.WritePacket(file, Packet_Size, CompactNum.GetBytes(Size));

                return(protocol.WriteFinish());
            }
        }
示例#31
0
文件: TempCache.cs 项目: nandub/DeOps
        public override byte[] Encode(G2Protocol protocol)
        {
            lock (protocol.WriteSection)
            {
                G2Frame temp = protocol.WritePacket(null, TempPacket.Data, null);

                protocol.WritePacket(temp, Packet_TTL, CompactNum.GetBytes(TTL));
                protocol.WritePacket(temp, Packet_Data, Data);

                return(protocol.WriteFinish());
            }
        }
示例#32
0
        internal override byte[] Encode(G2Protocol protocol)
        {
            lock (protocol.WriteSection)
            {
                G2Frame root = protocol.WritePacket(null, SharingPacket.Collection, null);

                protocol.WritePacket(root, Packet_Hash, Hash);
                protocol.WritePacket(root, Packet_Size, CompactNum.GetBytes(Size));
                protocol.WritePacket(root, Packet_Key,  Key);

                return protocol.WriteFinish();
            }
        }
示例#33
0
        internal override byte[] Encode(G2Protocol protocol)
        {
            lock (protocol.WriteSection)
            {
                G2Frame root = protocol.WritePacket(null, SharingPacket.File, null);

                protocol.WritePacket(root, Packet_Name, UTF8Encoding.UTF8.GetBytes(Name));
                protocol.WritePacket(root, Packet_Hash, Hash);
                protocol.WritePacket(root, Packet_Size, CompactNum.GetBytes(Size));
                protocol.WritePacket(root, Packet_FileKey, FileKey);

                if (SaveLocal)
                {
                    if (SystemPath != null)
                        protocol.WritePacket(root, Packet_SystemPath, UTF8Encoding.UTF8.GetBytes(SystemPath));

                    if (Public)
                        protocol.WritePacket(root, Packet_Public, null);
                }

                return protocol.WriteFinish();
            }
        }