Beispiel #1
0
        public void Register()
        {
            var registerMessage = new Message
            {
                Type         = MessageType.Register,
                LocalAddress = InterfaceHelper.GetLocalAddress().GetAddressBytes()
            };

            _logger.LogInformation($"Registering to {ServerEndPoint.Address}");
            UdpSocket.SendMessageTo(ServerEndPoint, registerMessage);
            IPEndPoint remote;
            var        message          = UdpSocket.RecvMessage(out remote);
            var        virtualIPAddress = new IPAddress(message.VirtualAddress);

            _logger.LogInformation("MessageType={type}, VA={virtualAddress}", message.Type, virtualIPAddress);

            if (message.Type != MessageType.RegisterSuccess)
            {
                throw new AliceException("Cannot register on server");
            }
            SessionId = message.SessionId;
            Tun.SetIP(virtualIPAddress);
            Tun.SetMask("255.255.255.0");
        }