Example #1
0
 public ZmqTransport(IZmqTransportConfiguration configuration, ZmqSocketOptions socketOptions, IZmqOutboundSocketErrorHandler errorHandler)
 {
     _configuration             = configuration;
     _errorHandler              = errorHandler;
     _configuredInboundEndPoint = new ZmqEndPoint(configuration.InboundEndPoint);
     SocketOptions              = socketOptions;
 }
Example #2
0
        private ZmqInboundSocket CreateInboundSocket(InboundProcStartSequenceState state)
        {
            ZmqInboundSocket inboundSocket = null;

            try
            {
                inboundSocket        = new ZmqInboundSocket(_context, PeerId, _configuredInboundEndPoint, _socketOptions, _environment);
                _realInboundEndPoint = inboundSocket.Bind();
                return(inboundSocket);
            }
            catch (Exception ex)
            {
                state.SetFailed(ex);
                if (inboundSocket != null)
                {
                    inboundSocket.Dispose();
                }

                return(null);
            }
            finally
            {
                state.Release();
            }
        }
Example #3
0
        public ZmqEndPoint Bind()
        {
            _socket = CreateSocket();

            _endPoint = new ZmqEndPoint(_originalEndpoint.Value);
            if (_endPoint.HasRandomPort)
            {
                _endPoint.SelectRandomPort(_peerId, _environment);
            }

            _socket.Bind(_endPoint.Value);


            try
            {
                _endPoint.SavePort(_peerId, _environment);
            }
            catch (Exception ex)
            {
                _logger.Error("Impossible to write inbound port file.", ex);
            }

            var endPointWithIp = new ZmqEndPoint(_socket.LastEndpoint);

            _logger.InfoFormat("Socket bound, Inbound EndPoint: {0}", endPointWithIp.Value);

            return(endPointWithIp);
        }
Example #4
0
 public ZmqInboundSocket(ZmqContext context, PeerId peerId, ZmqEndPoint originalEndpoint, ZmqSocketOptions options, string environment)
 {
     _context          = context;
     _peerId           = peerId;
     _originalEndpoint = originalEndpoint;
     _options          = options;
     _environment      = environment;
 }
Example #5
0
 public ZmqInboundSocket(ZmqContext context, PeerId peerId, ZmqEndPoint originalEndpoint, IZmqSocketOptions options, string environment)
 {
     _context = context;
     _peerId = peerId;
     _originalEndpoint = originalEndpoint;
     _options = options;
     _environment = environment;
 }
Example #6
0
        public ZmqEndPoint Bind()
        {
            _socket = CreateSocket();

            _endPoint = new ZmqEndPoint(_originalEndpoint.Value); 
            if (_endPoint.HasRandomPort)
                _endPoint.SelectRandomPort(_peerId, _environment);

            _socket.Bind(_endPoint.Value);

            var endPointWithIp = new ZmqEndPoint(_socket.LastEndpoint);
            _logger.InfoFormat("Socket bound, Inbound EndPoint: {0}", endPointWithIp.Value);

            return endPointWithIp;
        }
Example #7
0
        public ZmqEndPoint Bind()
        {
            _socket = CreateSocket();

            _endPoint = new ZmqEndPoint(_originalEndpoint.Value);
            if (_endPoint.HasRandomPort)
            {
                _endPoint.SelectRandomPort(_peerId, _environment);
            }

            _socket.Bind(_endPoint.Value);

            var endPointWithIp = new ZmqEndPoint(_socket.LastEndpoint);

            _logger.InfoFormat("Socket bound, Inbound EndPoint: {0}", endPointWithIp.Value);

            return(endPointWithIp);
        }
Example #8
0
        public ZmqEndPoint Bind()
        {
            _socket = CreateSocket();

            var endPoint = new ZmqEndPoint(_originalEndpoint.Value);

            if (endPoint.HasRandomPort)
            {
                endPoint.SelectRandomPort(_environment);
            }

            _socket.Bind(endPoint.Value);

            _socketEndPoint = new ZmqEndPoint(_socket.GetOptionString(ZmqSocketOption.LAST_ENDPOINT));
            _logger.InfoFormat("Socket bound, Inbound EndPoint: {0}", _socketEndPoint.Value);

            return(_socketEndPoint);
        }
Example #9
0
 public ZmqTransport(IZmqTransportConfiguration configuration, IZmqSocketOptions socketOptions)
 {
     _configuration             = configuration;
     _configuredInboundEndPoint = new ZmqEndPoint(configuration.InboundEndPoint);
     SocketOptions = socketOptions;
 }
Example #10
0
        public void should_not_reuse_a_port_used_in_another_envionment()
        {
            const string peerId = "Abc.Peer.0";

            var doNotUsePortFilePath = PathUtil.InBaseDirectory(peerId + ".inboundport.secondenv");
            var expectedPort = TcpUtil.GetRandomUnusedPort() + 5; // scientifical method to determine what port will be used by the transport :P

            File.WriteAllText(doNotUsePortFilePath, expectedPort.ToString());

            var transport = CreateAndStartZmqTransport(peerId: peerId);
            var endpoint = new ZmqEndPoint(transport.InboundEndPoint);

            endpoint.GetPort().ShouldNotEqual(expectedPort);
            Console.WriteLine("{0} => {1}", endpoint.GetPort(), expectedPort);
        }