Exemplo n.º 1
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));
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
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);
        }