コード例 #1
0
        public void Can_Validate_PeerId_Format()
        {
            _peerIdValidator.ValidatePeerIdFormat(_validPeerId);

            _output.WriteLine(string.Join(" ", _validPeerId.ToByteArray()));
            var fieldsInBytes = new[]
            {
                _validPeerId.Ip.ToByteArray(), BitConverter.GetBytes(_validPeerId.Port),
                _validPeerId.PublicKey.ToByteArray()
            };

            _output.WriteLine(string.Join(" ", fieldsInBytes.SelectMany(b => b)));
        }
コード例 #2
0
ファイル: PeerAddress.cs プロジェクト: lanicon/TomP2P.NET
        /// <summary>
        /// Serializes to an existing array.
        /// </summary>
        /// <param name="me">The array where the result should be stored.</param>
        /// <param name="offset">The offset where to start to save the result in the byte array.</param>
        /// <returns>The new offset.</returns>
        public int ToByteArray(sbyte[] me, int offset)
        {
            // save the peer ID
            int newOffset = offset;

            me[newOffset++] = Options;
            me[newOffset++] = Relays;
            newOffset       = PeerId.ToByteArray(me, newOffset);

            // we store both the addresses of the peer and the relays
            // currently, this is not needed as we don't consider asymmetric relays
            newOffset = PeerSocketAddress.ToByteArray(me, newOffset);

            foreach (var psa in PeerSocketAddresses)
            {
                newOffset = psa.ToByteArray(me, newOffset);
            }

            return(newOffset);
        }