Exemplo n.º 1
0
 public void sendChatMessage(String chat_message)
 {
     xbs_node_message_chatmsg msg = new xbs_node_message_chatmsg(this, chat_message);
     sendNodeMessage(msg);
 }
Exemplo n.º 2
0
        public void dispatch_in_msg(ref xbs_udp_message udp_msg)
        {
            xbs_node tmp_node = null;
            xbs_node sending_node = node_list.findNode(udp_msg.src_ip, udp_msg.src_port);
# if DEBUG
            if (udp_msg.msg_type != xbs_node_message_type.PING && udp_msg.msg_type != xbs_node_message_type.PONG)
            {
                String str_send_node = (sending_node == null) ? udp_msg.src_ip + ":" + udp_msg.src_port : sending_node.ToString() + " " + sending_node.nickname;
                //xbs_messages.addDebugMessage(" * IN " + udp_msg.msg_type + " " + str_send_node, xbs_message_sender.UDP_LISTENER);
            }
# endif
            switch (udp_msg.msg_type)
            {
                case xbs_node_message_type.DATA:
                    dispatch_DATA_message(ref udp_msg, ref sending_node);
                    break;

                case xbs_node_message_type.ANNOUNCE:
                    xbs_node_message_announce msg_announce = new xbs_node_message_announce(udp_msg.data);
                    tmp_node = new xbs_node(udp_msg.src_ip, udp_msg.src_port);
#if DEBUG
                    StringBuilder options_string = new StringBuilder();
                    foreach (KeyValuePair<string, string> item in msg_announce.getAllOptions())
                        options_string.Append(item.Key + "=" + item.Value + " ; ");
                    xbs_messages.addDebugMessage(" * IN ANNOUCE: " + tmp_node + " | options: " + options_string.ToString(), xbs_message_sender.UDP_LISTENER);
#endif
                    bool send_packet = true;
                    if (msg_announce.hasOption(xbs_node_message_announce.OPTION_CLOUDNAME))
                        if (!msg_announce.getOption(xbs_node_message_announce.OPTION_CLOUDNAME).Equals(xbs_cloudlist.getInstance().current_cloudname))
                            send_packet = false;
                    if (send_packet)
                        tmp_node.sendAddNodeMessage(node_list.local_node);
                    break;

                case xbs_node_message_type.KNOWNNODE:
                    xbs_node_message_knownnode msg_knownnode = new xbs_node_message_knownnode(udp_msg.data);
                    
                    // only accept KNOWNNODE messages when not part of a cloud
                    if (!xbs_cloudlist.getInstance().part_of_cloud)
                    {
                        tmp_node = node_list.findNode(msg_knownnode.ip, msg_knownnode.port);
                        if (tmp_node == null)
                        {
                            tmp_node = new xbs_node(msg_knownnode.ip, msg_knownnode.port);
#if DEBUG
                        xbs_messages.addDebugMessage(" * trying to add known node: " + tmp_node, xbs_message_sender.UDP_LISTENER);
#endif
                            node_list.tryAddingNode(tmp_node, xbs_cloudlist.getInstance().current_cloudname);
                        }
#if DEBUG
                        else
                            xbs_messages.addDebugMessage(" * already in contact with node: " + tmp_node, xbs_message_sender.UDP_LISTENER);
#endif
                    }

                    break;

                case xbs_node_message_type.ADDNODE:
                    xbs_node_message_addnode msg_addnode = new xbs_node_message_addnode(udp_msg.data);
# if DEBUG
                    xbs_messages.addDebugMessage(" * received ADDNODE from " + udp_msg.src_ip + ":" + udp_msg.src_port + " for " + msg_addnode.ip + ":" + msg_addnode.port, xbs_message_sender.UDP_LISTENER);
# endif
                    if (sending_node == null)
                    {   // node not known, add to nodelist
                        tmp_node = node_list.addNode(msg_addnode.ip, msg_addnode.port, udp_msg.src_ip, udp_msg.src_port);
                        tmp_node.sendAddNodeMessage(node_list.local_node);
                        if (!xbs_cloudlist.getInstance().part_of_cloud)
                            node_list.sendNodeListToNode(tmp_node);
                    }
                    break;

                case xbs_node_message_type.DELNODE:
                    xbs_node_message_delnode msg_delnode = new xbs_node_message_delnode(udp_msg.data);
# if DEBUG  
                    xbs_messages.addDebugMessage(" * received DELNODE from " + udp_msg.src_ip + ":" + udp_msg.src_port + " for " + msg_delnode.ip + ":" + msg_delnode.port, xbs_message_sender.UDP_LISTENER);
# endif
                    try
                    {
                        tmp_node = node_list.delNode(udp_msg.src_ip, (UInt16)udp_msg.src_port);
                    }
                    catch (Exception ex)
                    {
                        xbs_messages.addInfoMessage("!! error on deleting node: " + ex.Message, xbs_message_sender.UDP_LISTENER, xbs_message_type.ERROR);
                    }
                    if (tmp_node != null && xbs_chat.message_when_nodes_join_or_leave)
                        xbs_chat.addSystemMessage(tmp_node.nickname + " left.");
                    break;

                case xbs_node_message_type.PING:
                    tmp_node = (sending_node != null) ? sending_node : new xbs_node(udp_msg.src_ip, udp_msg.src_port);
                    xbs_node_message_pong msg_pong = new xbs_node_message_pong(tmp_node, udp_msg.data);
                    tmp_node.sendNodeMessage(msg_pong);
                    break;

                case xbs_node_message_type.PONG:
                    if (sending_node != null)
                    {
                        sending_node.pong(xbs_node_message_pong.getDelay(udp_msg.data).Milliseconds);
                        node_list.listHasJustChanged();
                    }
                    break;

                case xbs_node_message_type.GETNODELIST:
                    tmp_node = (sending_node != null) ? sending_node : new xbs_node(udp_msg.src_ip, udp_msg.src_port);
                    node_list.sendNodeListToNode(tmp_node);
                    break;
                
                case xbs_node_message_type.GETCLIENTVERSION:
                    tmp_node = (sending_node != null) ? sending_node : new xbs_node(udp_msg.src_ip, udp_msg.src_port);
                    xbs_node_message_clientversion msg_gcv = new xbs_node_message_clientversion(tmp_node, xbs_settings.xbslink_version);
                    tmp_node.sendNodeMessage(msg_gcv);
                    break;

                case xbs_node_message_type.CLIENTVERSION:
                    if (sending_node != null)
                    {
                        xbs_node_message_clientversion msg_cv = new xbs_node_message_clientversion(udp_msg.data);
                        sending_node.client_version = msg_cv.version_string;
                        node_list.listHasJustChanged();
                    }
                    break;
                case xbs_node_message_type.CHATMSG:
                    if (sending_node != null)
                    {
                        xbs_node_message_chatmsg msg_chat = new xbs_node_message_chatmsg(udp_msg.data);
                        xbs_chat.addChatMessage(sending_node.nickname, msg_chat.getChatMessage());
                    }
                    break;
                case xbs_node_message_type.NICKNAME:
                    if (sending_node != null)
                    {
                        xbs_node_message_nickname msg_nick = new xbs_node_message_nickname(udp_msg.data);
                        sending_node.nickname = msg_nick.getNickname();
                        sending_node.nickname_received = true;
                        node_list.listHasJustChanged();
                        if ( xbs_chat.message_when_nodes_join_or_leave )
                            xbs_chat.addSystemMessage(sending_node.nickname + " joined.");
                    }
                    break;
                case xbs_node_message_type.GETNICKNAME:
                    tmp_node = (sending_node!=null) ? sending_node : new xbs_node(udp_msg.src_ip, udp_msg.src_port);
                    xbs_node_message_nickname msg_snick = new xbs_node_message_nickname(tmp_node, node_list.local_node.nickname);
                    tmp_node.sendNodeMessage(msg_snick);
                    break;
                case xbs_node_message_type.SERVERHELLO:
                    lock (_locker_HELLO)
                    {
                        xbs_upnp.isPortReachable = true;
                        Monitor.PulseAll(_locker_HELLO);
                    }
                    break;
                case xbs_node_message_type.TO_CLOUDHELPER_HELPWITHNODE:
                    xbs_node_message_toCloudHelper_HelpWithNode msg_toCloudHelpWith = new xbs_node_message_toCloudHelper_HelpWithNode(udp_msg.data);
                    node_list.cloudhelper_helpWithNode(udp_msg.src_ip, udp_msg.src_port, msg_toCloudHelpWith.ip, msg_toCloudHelpWith.port);
                    break;
                case xbs_node_message_type.FROM_CLOUDHELPER_CONTACTNODE:
                    xbs_node_message_fromCloudHelper_ContactNode msg_fromCloudContactNode = new xbs_node_message_fromCloudHelper_ContactNode(udp_msg.data);
                    tmp_node = new xbs_node(msg_fromCloudContactNode.ip, msg_fromCloudContactNode.port);
                    node_list.tryAddingNode(tmp_node, xbs_cloudlist.getInstance().current_cloudname);
                    break;
            }

            if (sending_node != null)
                sending_node.statistics.receivedPacket((uint)udp_msg.data_len + xbs_udp_message.HEADER_LENGTH);
        }
Exemplo n.º 3
0
        public void sendChatMessage(String chat_message)
        {
            xbs_node_message_chatmsg msg = new xbs_node_message_chatmsg(this, chat_message);

            sendNodeMessage(msg);
        }