/// <summary> /// Send a message to the peer using a stream. /// </summary> /// <param name="metadata">Dictionary containing metadata.</param> /// <param name="contentLength">The amount of data to read from the stream.</param> /// <param name="stream">The stream containing the data.</param> /// <returns>True if successful.</returns> public bool Send(Dictionary <object, object> metadata, long contentLength, Stream stream) { if (contentLength < 0) { throw new ArgumentException("Content length must be zero or greater."); } if (stream == null || !stream.CanRead) { throw new ArgumentException("Cannot read from supplied stream."); } if (_ClusterClient != null) { if (_ClusterClient.Connected) { return(_ClusterClient.Send(metadata, contentLength, stream)); } } else if (String.IsNullOrEmpty(_CurrPeerIpPort)) { Logger?.Invoke("[ClusterNode] No peer connected"); return(false); } else if (_ClusterServer != null) { if (_ClusterServer.IsConnected(_CurrPeerIpPort)) { return(_ClusterServer.Send(_CurrPeerIpPort, metadata, contentLength, stream)); } } Logger?.Invoke("[ClusterNode] Neither server or client are healthy"); return(false); }
/// <summary> /// Send a message to the peer node. /// </summary> /// <param name="data">Data to send to the peer node.</param> /// <returns>True if successful.</returns> public bool Send(byte[] data) { if (_ClusterClient != null) { if (_ClusterClient.Connected) { return(_ClusterClient.Send(data)); } } else if (String.IsNullOrEmpty(_CurrPeerIpPort)) { if (Debug) { Console.WriteLine("No peer connected"); } return(false); } else if (_ClusterServer != null) { if (_ClusterServer.IsConnected(_CurrPeerIpPort)) { return(_ClusterServer.Send(_CurrPeerIpPort, data)); } } if (Debug) { Console.WriteLine("Neither server or client are healthy"); } return(false); }
/// <summary> /// Determine if the cluster is healthy (i.e. both nodes are bidirectionally connected). /// </summary> /// <returns>True if healthy.</returns> public bool IsHealthy() { if (Server == null) { if (Debug) { Console.WriteLine("Server object is null"); } return(false); } if (Client == null) { if (Debug) { Console.WriteLine("Client object is null"); } return(false); } if (String.IsNullOrEmpty(CurrPeerIpPort)) { if (Debug) { Console.WriteLine("Peer information is null"); } return(false); } if (!Server.IsConnected(CurrPeerIpPort)) { if (Debug) { Console.WriteLine("Server peer is not connected"); } return(false); } if (Client.IsConnected()) { if (Debug) { Console.WriteLine("Client is not connected"); } return(true); } return(false); }
/// <summary> /// Send a message to the peer node using a stream. /// </summary> /// <param name="contentLength">The amount of data to read from the stream.</param> /// <param name="stream">The stream containing the data.</param> /// <returns>True if successful.</returns> public async Task <bool> Send(long contentLength, Stream stream) { if (contentLength < 0) { throw new ArgumentException("Content length must be zero or greater."); } if (stream == null || !stream.CanRead) { throw new ArgumentException("Cannot read from supplied stream."); } if (_ClusterClient != null) { if (_ClusterClient.Connected) { return(await _ClusterClient.Send(contentLength, stream)); } } else if (String.IsNullOrEmpty(_CurrPeerIpPort)) { if (Debug) { Log("No peer connected"); } return(false); } else if (_ClusterServer != null) { if (_ClusterServer.IsConnected(_CurrPeerIpPort)) { return(await _ClusterServer.Send(_CurrPeerIpPort, contentLength, stream)); } } if (Debug) { Log("Neither server or client are healthy"); } return(false); }