Ejemplo n.º 1
0
        public Metainfo ToMetainfo(out byte[] bytes)
        {
            BencodedValue entries = Build();

            bytes = Bencoder.Encode(entries);
            return(MetainfoFactory.FromBytes(bytes));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 3
0
        public byte[] ToBytes()
        {
            BencodedValue entries = Build();

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

            return(bytes);
        }
Ejemplo n.º 4
0
        public Extended GetHandshake()
        {
            BencodedValue encoded = more.Encode(metadata?.Size);

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

            return(new Extended(0, binary));
        }
Ejemplo n.º 5
0
        public FileHash ToHash()
        {
            BencodedValue entries = Build();

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

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

            return(hash);
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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);
        }