Пример #1
0
        public Metainfo ToMetainfo(out byte[] bytes)
        {
            BencodedValue entries = Build();

            bytes = Bencoder.Encode(entries);
            return(MetainfoFactory.FromBytes(bytes));
        }
Пример #2
0
        public static void SendMetadataRequest(this CoordinatorService glue, PeerHash peer, int piece)
        {
            BencodedValue bencoded = new BencodedValue
            {
                Dictionary = new[]
                {
                    new BencodedEntry
                    {
                        Key = new BencodedValue {
                            Text = new BencodedText("msg_type")
                        },
                        Value = new BencodedValue {
                            Number = new BencodedNumber(0)
                        }
                    },
                    new BencodedEntry
                    {
                        Key = new BencodedValue {
                            Text = new BencodedText("piece")
                        },
                        Value = new BencodedValue {
                            Number = new BencodedNumber(piece)
                        }
                    }
                }
            };

            glue.SendExtension(peer, MetadataPlugin.Name, Bencoder.Encode(bencoded));
        }
Пример #3
0
        public byte[] ToBytes()
        {
            BencodedValue entries = Build();

            byte[] bytes = Bencoder.Encode(entries);

            return(bytes);
        }
Пример #4
0
        public Extended GetHandshake()
        {
            BencodedValue encoded = more.Encode(metadata?.Size);

            byte[] binary = Bencoder.Encode(encoded);

            return(new Extended(0, binary));
        }
Пример #5
0
        public FileHash ToHash()
        {
            BencodedValue entries = Build();

            byte[] bytes = Bencoder.Encode(entries);

            Metainfo metainfo = MetainfoFactory.FromBytes(bytes);
            FileHash hash     = metainfo.Hash;

            return(hash);
        }
Пример #6
0
        public static void SendPeers(this CoordinatorService glue, PeerHash peer, params NetworkAddress[] remotes)
        {
            BencodedValue bencoded = new BencodedValue
            {
                Dictionary = new[]
                {
                    new BencodedEntry
                    {
                        Key = new BencodedValue {
                            Text = new BencodedText("added")
                        },
                        Value = new BencodedValue {
                            Data = ToData(remotes)
                        }
                    }
                }
            };

            glue.SendExtension(peer, PeersPlugin.Name, Bencoder.Encode(bencoded));
        }
Пример #7
0
        public static void SendMetadataPiece(this CoordinatorService glue, PeerHash peer, int piece, int total, byte[] data)
        {
            BencodedValue bencoded = new BencodedValue
            {
                Dictionary = new[]
                {
                    new BencodedEntry
                    {
                        Key = new BencodedValue {
                            Text = new BencodedText("msg_type")
                        },
                        Value = new BencodedValue {
                            Number = new BencodedNumber(1)
                        }
                    },
                    new BencodedEntry
                    {
                        Key = new BencodedValue {
                            Text = new BencodedText("piece")
                        },
                        Value = new BencodedValue {
                            Number = new BencodedNumber(piece)
                        }
                    },
                    new BencodedEntry
                    {
                        Key = new BencodedValue {
                            Text = new BencodedText("total_size")
                        },
                        Value = new BencodedValue {
                            Number = new BencodedNumber(total)
                        }
                    }
                }
            };

            byte[] payload = Bencoder.Encode(bencoded);

            Bytes.Append(ref payload, data);
            glue.SendExtension(peer, MetadataPlugin.Name, payload);
        }