1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-24 17:28:08 +00:00

Remove UDP server discovery because not use for the moment

This commit is contained in:
Julien Duponchelle 2017-03-21 17:04:59 +01:00
parent cc6f4c0510
commit 1566d7f12a
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
2 changed files with 1 additions and 73 deletions

View File

@ -26,9 +26,7 @@ import datetime
import sys import sys
import locale import locale
import argparse import argparse
import shutil
import psutil import psutil
import asyncio
from gns3server.web.web_server import WebServer from gns3server.web.web_server import WebServer
@ -107,7 +105,6 @@ def parse_arguments(argv):
parser.add_argument("--daemon", action="store_true", help="start as a daemon") parser.add_argument("--daemon", action="store_true", help="start as a daemon")
parser.add_argument("--pid", help="store process pid") parser.add_argument("--pid", help="store process pid")
parser.add_argument("--profile", help="Settings profile (blank will use default settings files)") parser.add_argument("--profile", help="Settings profile (blank will use default settings files)")
parser.add_argument("--discovery", action="store_true", help="Make server discoverable on the network")
args = parser.parse_args(argv) args = parser.parse_args(argv)
if args.config: if args.config:
@ -128,8 +125,7 @@ def parse_arguments(argv):
"allow": config.getboolean("allow_remote_console", False), "allow": config.getboolean("allow_remote_console", False),
"quiet": config.getboolean("quiet", False), "quiet": config.getboolean("quiet", False),
"debug": config.getboolean("debug", False), "debug": config.getboolean("debug", False),
"logfile": config.getboolean("logfile", ""), "logfile": config.getboolean("logfile", "")
"server_discovery": config.getboolean("server_discovery", False)
} }
parser.set_defaults(**defaults) parser.set_defaults(**defaults)

View File

@ -22,11 +22,7 @@ Set up and run the server.
import os import os
import sys import sys
import signal import signal
import socket
import json
import ipaddress
import asyncio import asyncio
import threading
import aiohttp import aiohttp
import aiohttp_cors import aiohttp_cors
import functools import functools
@ -38,7 +34,6 @@ from ..config import Config
from ..compute import MODULES from ..compute import MODULES
from ..compute.port_manager import PortManager from ..compute.port_manager import PortManager
from ..controller import Controller from ..controller import Controller
from ..version import __version__
# do not delete this import # do not delete this import
@ -191,64 +186,6 @@ class WebServer:
atexit.register(close_asyncio_loop) atexit.register(close_asyncio_loop)
def _udp_server_discovery(self):
"""
UDP multicast and broadcast server discovery (Linux only)
"""
import ctypes
uint32_t = ctypes.c_uint32
in_addr_t = uint32_t
class in_addr(ctypes.Structure):
_fields_ = [('s_addr', in_addr_t)]
class in_pktinfo(ctypes.Structure):
_fields_ = [('ipi_ifindex', ctypes.c_int),
('ipi_spec_dst', in_addr),
('ipi_addr', in_addr)]
IP_PKTINFO = 8
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock:
membership = socket.inet_aton("239.42.42.1") + socket.inet_aton("0.0.0.0")
sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, membership)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
sock.setsockopt(socket.SOL_IP, IP_PKTINFO, 1)
try:
sock.bind(("", self._port))
except OSError as e:
log.error("UDP server discovery could not bind on port {}: {}".format(self._port, e))
return
log.info("UDP server discovery started on port {}".format(self._port))
while self._loop.is_running():
try:
data, ancdata, _, address = sock.recvmsg(255, socket.CMSG_LEN(255))
except OSError as e:
log.error("Error while receiving UDP server discovery request: {}".format(e))
continue
cmsg_level, cmsg_type, cmsg_data = ancdata[0]
if cmsg_level == socket.SOL_IP and cmsg_type == IP_PKTINFO:
pktinfo = in_pktinfo.from_buffer_copy(cmsg_data)
request_address = ipaddress.IPv4Address(memoryview(pktinfo.ipi_addr).tobytes())
receiving_interface = socket.if_indextoname(pktinfo.ipi_ifindex)
log.debug("UDP server discovery request received on {} using {}".format(receiving_interface,
request_address))
local_address = ipaddress.IPv4Address(memoryview(pktinfo.ipi_spec_dst).tobytes())
if self._host != "0.0.0.0" and self._host != str(local_address):
log.debug("Ignoring UDP discovery request received on {} instead of {}".format(local_address,
self._host))
continue
server_info = {"version": __version__,
"ip": str(local_address),
"port": self._port}
data = json.dumps(server_info)
sock.sendto(data.encode(), address)
log.debug("Sent server info to {}:{} {}".format(address[0], address[1], data))
time.sleep(1) # this is to prevent too many request to slow down the server
log.debug("UDP server discovery stopped")
def run(self): def run(self):
""" """
Starts the server. Starts the server.
@ -322,11 +259,6 @@ class WebServer:
if server_config.getboolean("shell"): if server_config.getboolean("shell"):
asyncio.async(self.start_shell()) asyncio.async(self.start_shell())
if sys.platform.startswith("linux") and server_config.getboolean("server_discovery"):
# UDP discovery is only supported on Linux
udp_server_discovery = threading.Thread(target=self._udp_server_discovery, daemon=True)
udp_server_discovery.start()
try: try:
self._loop.run_forever() self._loop.run_forever()
except TypeError as e: except TypeError as e: