Beispiel #1
0
        //
        public void NewConnection(string address, string identifier)
        {
            channel = new Channel(address, ChannelCredentials.Insecure);
            Client  = new CodeLiquidService.CodeLiquidServiceClient(channel);

            ConnectReply reply = Client.Connect(new ConnectRequest
            {
                Username = "******",
            });

            connectionId = reply.ConnectionId;

            Metadata metadata = new Metadata();

            metadata.Add("connectionId", connectionId.ToString());

            Streams = new Streams
            {
                Move   = Client.Move(metadata),
                Jump   = Client.Jump(metadata),
                Sprint = Client.Sprint(metadata),
                Chat   = Client.Chat(metadata),
            };

            Listener.Listen(Streams.Move);
            Listener.Listen(Streams.Jump);
            Listener.Listen(Streams.Sprint);
            Listener.Listen(Streams.Chat);
        }
Beispiel #2
0
        public void connectRequest(KernelMessage msg, ConnectRequest content)
        {
            var reply = new ConnectReply()
            {
                hb_port    = connectionInformation.hb_port,
                iopub_port = connectionInformation.iopub_port,
                shell_port = connectionInformation.shell_port,
                stdin_port = connectionInformation.stdin_port
            };

            logMessage("connectRequest()");
            sendMessage(shellSocket, msg, "connect_reply", reply);
        }
Beispiel #3
0
        /// <summary>
        /// Given an IP address, will create a connection to the distant node for
        /// further communications.
        /// </summary>
        /// <returns>The created peer</returns>
        public async Task <GrpcPeer> DialPeerAsync(IPEndPoint endpoint)
        {
            var client         = CreateClient(endpoint);
            var connectionInfo = await _connectionInfoProvider.GetConnectionInfoAsync();

            ConnectReply connectReply = await CallConnectAsync(client, endpoint, connectionInfo);

            if (connectReply?.Info?.Pubkey == null || connectReply.Error != ConnectError.ConnectOk)
            {
                await CleanupAndGetExceptionAsync($"Connect error: {connectReply?.Error}.", client.Channel);
            }

            return(new GrpcPeer(client, endpoint, connectReply.Info.ToPeerInfo(isInbound: false)));
        }
Beispiel #4
0
        /// <summary>
        /// Calls the server side connect RPC method, in order to establish a 2-way connection.
        /// </summary>
        /// <returns>The reply from the server.</returns>
        private async Task <ConnectReply> CallConnectAsync(GrpcClient client, IPEndPoint ipAddress,
                                                           ConnectionInfo connectionInfo)
        {
            ConnectReply connectReply = null;

            try
            {
                var metadata = new Metadata {
                    { GrpcConstants.TimeoutMetadataKey, (NetworkOptions.PeerDialTimeoutInMilliSeconds * 2).ToString() }
                };

                connectReply = await client.Client.ConnectAsync(new ConnectRequest { Info = connectionInfo }, metadata);
            }
            catch (AggregateException ex)
            {
                await CleanupAndGetExceptionAsync($"Could not connect to {ipAddress}.", client.Channel, ex);
            }

            return(connectReply);
        }