Exemplo n.º 1
0
 //------------------------------------------------------------------------------------------------------------------------
 private void RemoteNode_OnChannelOpen(RemoteNode RemoteNode)
 {
     BrotherNodes.Add(RemoteNode.RemoteNodeKey, RemoteNode);
     //raise event
     if (OnRemoteNodeAssociation != null)
     {
         Task.Run(() => { try { OnRemoteNodeAssociation?.Invoke(RemoteNode); } catch (Exception ex) { DebugEx.Assert(ex, "Unhandled exception"); } });
     }
 }
Exemplo n.º 2
0
 //------------------------------------------------------------------------------------------------------------------------
 private void RemoteNode_OnVBMReceived(RemoteNode RemoteNode, VirtualBlockEventMsg msg)
 {
     OnVBMReceived?.Invoke(RemoteNode.RemoteNodeKey, msg);
 }
Exemplo n.º 3
0
 //------------------------------------------------------------------------------------------------------------------------
 void hookNewRemoteNodeEvents(RemoteNode remInfo)
 {
     remInfo.OnChannelOpen  += RemoteNode_OnChannelOpen;
     remInfo.OnChannelClose += RemoteNode_OnChannelClose;
     remInfo.OnVBMReceived  += RemoteNode_OnVBMReceived;
 }
Exemplo n.º 4
0
        //------------------------------------------------------------------------------------------------------------------------
        private void Discoverer_OnEndpointMsgRx(YPChannel.Transport.Sockets.LANDiscoverer.RemoteEndpointInfo endpoint, YPChannel.Transport.Sockets.IDiscoveryMessageBase __msg)
        {
            try
            {
                //get valid msg
                var msg = __msg as DiscoveryMessage;
                if (msg == null)
                {
                    return;
                }

                //create remotenodekey
                var rem_nodekey = API.Plegma.NodeKey.FromBytes(msg.NodeKey, 0);
                if (rem_nodekey.IsInvalid)
                {
                    return;
                }

                //examine existing association
                lock (RemoteNodes)
                {
                    var remInfo = RemoteNodes.TryGetOrDefault(endpoint.ID);
                    if (remInfo == null)
                    {
                        //inform
                        DebugEx.TraceLog($"NodeDiscoverer : Discovered new node. (ip:{endpoint.IPAddress} nodekey:{rem_nodekey})");

                        //create entry for remote node
                        remInfo = new RemoteNode(Node, TimeSpan.FromMinutes(5), this)
                        {
                            RemoteEndpointID = endpoint.ID,
                            DiscoveryMessage = msg,
                            RemoteNodeKey    = rem_nodekey,
                        };
                        //add to discovered remote nodes
                        RemoteNodes.Add(endpoint.ID, remInfo);

                        //hookevents
                        hookNewRemoteNodeEvents(remInfo);

                        //Start a connection attempt
                        remInfo.StartConnectionTask();

                        //raise event
                        if (OnRemoteNodeDiscovery != null)
                        {
                            Task.Run(() => { try { OnRemoteNodeDiscovery?.Invoke(remInfo); } catch (Exception ex) { DebugEx.Assert(ex, "Unhandled exception"); } });
                        }
                    }
                    else
                    {
                        //start remote node connection
                        if (!remInfo.IsDisposed &&
                            (remInfo.ClientChannel == null || (remInfo.ClientChannel.State == YPChannel.ChannelStates.Closed && !remInfo.ConnectionTaskRunning)))
                        {
                            remInfo.StartConnectionTask();
                        }
                    }
                }
            }
            catch (Exception ex) { DebugEx.TraceError(ex, "DiscoveryTaskEntryPoint error"); }
        }