public ActionResult <bool> Connect(PeerConnectRequest request) { if (_requiredConnection == null) { return(NotFound($"Cannot produce output because {nameof(NetworkRequiredConnection)} is not available")); } if (!LightningEndpoint.TryParse(request.EndPoint, out LightningEndpoint ipEndPoint)) { return(BadRequest("Incorrect endpoint")); } return(Ok(_requiredConnection.TryAddLightningEndPoint(ipEndPoint))); }
public bool TryGetEndPoint([MaybeNullWhen(false)] out LightningEndpoint?endPoint) { endPoint = null; if (LightningEndPoint == null) { return(false); } if (!LightningEndpoint.TryParse(LightningEndPoint, out endPoint)) { return(false); } return(true); }
/// <summary> /// Tries the add end point. /// /// </summary> /// <param name="endPoint">The end point.</param> /// <returns><see langword="true"/> if the endpoint has been added, <see langword="false"/> if the endpoint was already listed.</returns> public bool TryAddLightningEndPoint(LightningEndpoint endPoint) { endPoint.EndPoint = endPoint.EndPoint.AsIPEndPoint().EnsureIPv6(); if (connectionsToAttempt.Exists(ip => ip.Equals(endPoint))) { logger.LogDebug("EndPoint {RemoteEndPoint} already in the list of connections attempt.", endPoint); return(false); } else { var outgoingConnectionEndPoint = new OutgoingConnectionEndPoint(endPoint.EndPoint.AsIPEndPoint()); outgoingConnectionEndPoint.Items[nameof(LightningEndpoint)] = endPoint; connectionsToAttempt.Add(outgoingConnectionEndPoint); logger.LogDebug("EndPoint {RemoteEndPoint} added to the list of connections attempt.", endPoint); return(true); } }