/// <summary> /// Initializes a new instance of the <see cref="BoundPeer"/> class. /// </summary> /// <param name="publicKey">A <see cref="PublicKey"/> of the /// <see cref="Peer"/>.</param> /// <param name="endPoint">A <see cref="DnsEndPoint"/> consisting of the /// host and port of the <see cref="Peer"/>.</param> /// <param name="appProtocolVersion">An application protocol version /// that the <see cref="Peer"/> is using.</param> public BoundPeer( PublicKey publicKey, DnsEndPoint endPoint, AppProtocolVersion appProtocolVersion) : this(publicKey, endPoint, appProtocolVersion, null) { }
internal BoundPeer( PublicKey publicKey, DnsEndPoint endPoint, AppProtocolVersion appProtocolVersion, IPAddress publicIPAddress) : base(publicKey, appProtocolVersion, publicIPAddress) { EndPoint = endPoint ?? throw new ArgumentNullException(nameof(endPoint)); }
internal Peer( PublicKey publicKey, AppProtocolVersion appProtocolVersion, IPAddress publicIPAddress) { PublicKey = publicKey ?? throw new ArgumentNullException(nameof(publicKey)); AppProtocolVersion = appProtocolVersion; PublicIPAddress = publicIPAddress; }
/// <summary> /// Initializes a new instance of the /// <see cref="DifferentAppProtocolVersionException"/> class. /// </summary> /// <param name="expectedVersion">The protocol version of the current /// <see cref="Swarm{T}"/>.</param> /// <param name="actualVersion">The protocol version of the /// <see cref="Peer"/> that <see cref="Swarm{T}" /> is trying to connect /// to.</param> /// <param name="message">Specifies an <see cref="Exception.Message"/>. /// </param> public DifferentAppProtocolVersionException( string message, AppProtocolVersion expectedVersion, AppProtocolVersion actualVersion) : base($"{message}\n" + $"Expected Version: {expectedVersion} " + $"[{ByteUtil.Hex(expectedVersion.Signature)} by {expectedVersion.Signer}]\n" + $"Actual Version: {actualVersion} " + $"[{ByteUtil.Hex(actualVersion.Signature)} by {actualVersion.Signer}]") { ExpectedVersion = expectedVersion; ActualVersion = actualVersion; }
protected DifferentAppProtocolVersionException( SerializationInfo info, StreamingContext context) : base(info, context) { Peer = info.GetValue <Peer>(nameof(Peer)); Identity = info.GetValue <byte[]>(nameof(Identity)); ExpectedApv = AppProtocolVersion.FromToken( info.GetValue <string>(nameof(ExpectedApv))); ActualApv = AppProtocolVersion.FromToken( info.GetValue <string>(nameof(ActualApv))); Trusted = info.GetValue <bool>(nameof(Trusted)); }
/// <summary> /// Initializes a new instance of the /// <see cref="DifferentAppProtocolVersionException"/> class. /// </summary> /// <param name="message">Specifies an <see cref="Exception.Message"/>.</param> /// <param name="peer">The <see cref="Message.Remote"/> of the <see cref="Message"/> /// received.</param> /// <param name="identity">The <see cref="Message.Identity"/> of the <see cref="Message"/> /// received.</param> /// <param name="expectedAppProtocolVersion">The protocol version of /// the local <see cref="Swarm{T}"/>.</param> /// <param name="actualAppProtocolVersion">The protocol version of the <see cref="Peer"/> /// that the local <see cref="Swarm{T}"/> is trying to connect to.</param> /// <param name="trusted">Whether <paramref name="actualAppProtocolVersion"/> /// is signed by a trusted signer.</param> public DifferentAppProtocolVersionException( string message, Peer peer, byte[] identity, AppProtocolVersion expectedAppProtocolVersion, AppProtocolVersion actualAppProtocolVersion, bool trusted) : base(message) { Peer = peer; Identity = identity; ExpectedApv = expectedAppProtocolVersion; ActualApv = actualAppProtocolVersion; Trusted = trusted; }
/// <summary> /// Determines if the peer is compatible with the given criteria. /// </summary> /// <param name="localVersion">The version of the currently running application.</param> /// <param name="trustedSigners">A list of signers to trust. <em>An empty list means /// to trust no one, so that this method always returns <c>false</c>.</em> Conversely, /// <c>null</c> means to <em>trust anyone</em>. Be aware of the difference of those two. /// </param> /// <param name="recognizer">A callback to determine an encountered peer's /// <see cref="AppProtocolVersion"/> is compatible with the currently running /// application, in the case of the peer's version signature is trustworthy but its /// version number is not the same.</param> /// <returns><c>true</c> if the peer is compatible with the given criteria. /// Otherwise <c>false</c>.</returns> public bool IsCompatibleWith( AppProtocolVersion localVersion, IEnumerable <PublicKey> trustedSigners = null, DifferentAppProtocolVersionEncountered recognizer = null ) { if (AppProtocolVersion.Equals(localVersion)) { return(true); } if (trustedSigners is null || trustedSigners.Any(s => AppProtocolVersion.Verify(s))) { return(recognizer is null ? false : recognizer(this, AppProtocolVersion, localVersion)); } return(false); }
public Peer( PublicKey publicKey, AppProtocolVersion appProtocolVersion) : this(publicKey, appProtocolVersion, null) { }