public bool OnHandshake(IPeerWireClient client) { BDict handshakeDict = new BDict(); BDict mDict = new BDict(); byte i = 1; foreach (IBTExtension extension in _protocolExtensions) { _extOutgoing.Add(new ClientProtocolIDMap(client, extension.Protocol, i)); mDict.Add(extension.Protocol, new BInt(i)); i++; } handshakeDict.Add("m", mDict); String handshakeEncoded = BencodingUtils.EncodeString(handshakeDict); byte[] handshakeBytes = Encoding.ASCII.GetBytes(handshakeEncoded); Int32 length = 2 + handshakeBytes.Length; client.SendBytes((new byte[0]).Cat(Pack.Int32(length, Pack.Endianness.Big).Cat(new[] { (byte)20 }).Cat(new[] { (byte)0 }).Cat(handshakeBytes))); return true; }
public bool OnHandshake(IPeerWireClient client) { var handshakeDict = new BDict(); var mDict = new BDict(); byte i = 1; foreach (var extension in _protocolExtensions) { _extOutgoing.Add(new ClientProtocolIDMap(client, extension.Protocol, i)); mDict.Add(extension.Protocol, new BInt(i)); i++; } handshakeDict.Add("m", mDict); var handshakeEncoded = BencodingUtils.EncodeString(handshakeDict); var handshakeBytes = Encoding.ASCII.GetBytes(handshakeEncoded); var length = 2 + handshakeBytes.Length; client.SendBytes((new byte[0]).Cat(Pack.Int32(length, Pack.Endianness.Big).Cat(new[] { (byte)20 }).Cat(new[] { (byte)0 }).Cat(handshakeBytes))); return(true); }
public bool OnHandshake(IPeerWireClient client) { BDict handshakeDict = new BDict(); BDict mDict = new BDict(); byte i = 1; foreach (IBTExtension extension in this._protocolExtensions) { this._extOutgoing.Add(new ClientProtocolIDMap(client, extension.Protocol, i)); mDict.Add(extension.Protocol, new BInt(i)); i++; } handshakeDict.Add("m", mDict); string handshakeEncoded = BencodingUtils.EncodeString(handshakeDict); byte[] handshakeBytes = Encoding.ASCII.GetBytes(handshakeEncoded); Int32 length = 2 + handshakeBytes.Length; client.SendBytes((new byte[0]).Cat(PackHelper.Int32(length).Cat(new[] { (byte)20 }).Cat(new[] { (byte)0 }).Cat(handshakeBytes))); return(true); }
public void RequestMetaData(IPeerWireClient peerWireClient) { byte[] sendBuffer = new byte[0]; for (Int32 i = 0; i < this._pieceCount; i++) { BDict masterBDict = new BDict { { "msg_type", (BInt)0 }, { "piece", (BInt)i } }; string encoded = BencodingUtils.EncodeString(masterBDict); byte[] buffer = PackHelper.Int32(2 + encoded.Length); buffer = buffer.Concat(new byte[] { 20 }).ToArray(); buffer = buffer.Concat(new[] { this._parent.GetOutgoingMessageID(peerWireClient, this) }).ToArray(); buffer = buffer.Concat(Encoding.GetEncoding(1252).GetBytes(encoded)).ToArray(); sendBuffer = sendBuffer.Concat(buffer).ToArray(); } peerWireClient.SendBytes(sendBuffer); }
public void RequestMetaData(IPeerWireClient peerWireClient) { var sendBuffer = new byte[0]; for (Int32 i = 0; i < _pieceCount; i++) { var masterBDict = new BDict { { MESSAGE_TYPE_KEY, (BInt)0 }, { PIECE_KEY, (BInt)i } }; var encoded = BencodingUtils.EncodeString(masterBDict); var buffer = Pack.Int32(2 + encoded.Length, Pack.Endianness.Big); buffer = buffer.Concat(new byte[] { 20 }).ToArray(); buffer = buffer.Concat(new[] { _parent.GetOutgoingMessageID(peerWireClient, this) }).ToArray(); buffer = buffer.Concat(Encoding.GetEncoding(1252).GetBytes(encoded)).ToArray(); sendBuffer = sendBuffer.Concat(buffer).ToArray(); } peerWireClient.SendBytes(sendBuffer); }
public void RequestMetaData(IPeerWireClient peerWireClient) { byte[] sendBuffer = new byte[0]; for (Int32 i = 0; i < _pieceCount; i++) { BDict masterBDict = new BDict { {"msg_type", (BInt) 0}, {"piece", (BInt) i} }; String encoded = BencodingUtils.EncodeString(masterBDict); byte[] buffer = Pack.Int32(2 + encoded.Length, Pack.Endianness.Big); buffer = buffer.Concat(new byte[] {20}).ToArray(); buffer = buffer.Concat(new[] { _parent.GetOutgoingMessageID(peerWireClient, this) }).ToArray(); buffer = buffer.Concat(Encoding.GetEncoding(1252).GetBytes(encoded)).ToArray(); sendBuffer = sendBuffer.Concat(buffer).ToArray(); } peerWireClient.SendBytes(sendBuffer); }
public bool SendExtended(IPeerWireClient client, byte extMsgId, byte[] bytes) => client.SendBytes(new PeerMessageBuilder(20).Add(extMsgId).Add(bytes).Message());
public bool SendExtended(IPeerWireClient client, byte extMsgId, byte[] bytes) { return client.SendBytes(new PeerMessageBuilder(20).Add(extMsgId).Add(bytes).Message()); }