Removed DNS resolving as it was not needed

This commit is contained in:
CosminPerRam 2022-11-28 01:13:08 +02:00
parent 77a68e4a0c
commit 3d95f08ef4
4 changed files with 10 additions and 23 deletions

View file

@ -14,7 +14,8 @@ Who knows what the future holds...
[Arma 2: Operation Arrowhead](https://store.steampowered.com/app/33930/Arma_2_Operation_Arrowhead/) support.
Successfully tested `Alien Swarm` and `Insurgency: Modern Infantry Combat`.
Restored rules response for `Counter-Strike: Global Offensive` (note: for a full player list response, the cvar `host_players_show` must be set to `2`).
Increased Valve Protocol `PACKET_SIZE` from 1400 to 6144 (because some games send larger packets than the specified protocol size).
Increased Valve Protocol `PACKET_SIZE` from 1400 to 6144 (because some games send larger packets than the specified protocol size).
Removed DNS resolving as it was not needed.
# 0.0.5 - 15/11/2022
Added `SocketBind` error, regarding failing to bind a socket.

View file

@ -18,6 +18,4 @@ msrv = "1.58.1"
bzip2-rs = "0.1.2" # for compression
crc32fast = "1.3.2"
trust-dns-resolver = "0.22.0" # dns resolving
serde_json = "1.0.87" # json to structs

View file

@ -2,7 +2,7 @@ use std::io::{Read, Write};
use std::net;
use crate::{GDError, GDResult};
use crate::protocols::types::TimeoutSettings;
use crate::utils::complete_address;
use crate::utils::address_and_port_as_string;
static DEFAULT_PACKET_SIZE: usize = 1024;
@ -21,7 +21,7 @@ pub struct TcpSocket {
impl Socket for TcpSocket {
fn new(address: &str, port: u16) -> GDResult<Self> {
let complete_address = complete_address(address, port)?;
let complete_address = address_and_port_as_string(address, port)?;
let socket = net::TcpStream::connect(complete_address).map_err(|e| GDError::SocketConnect(e.to_string()))?;
Ok(Self {
@ -57,7 +57,7 @@ pub struct UdpSocket {
impl Socket for UdpSocket {
fn new(address: &str, port: u16) -> GDResult<Self> {
let complete_address = complete_address(address, port)?;
let complete_address = address_and_port_as_string(address, port)?;
let socket = net::UdpSocket::bind("0.0.0.0:0").map_err(|e| GDError::SocketBind(e.to_string()))?;
Ok(Self {

View file

@ -1,17 +1,5 @@
use trust_dns_resolver::config::{ResolverConfig, ResolverOpts};
use trust_dns_resolver::Resolver;
use crate::{GDResult, GDError};
fn resolve_dns(address: &str) -> GDResult<String> {
let resolver = Resolver::new(ResolverConfig::default(), ResolverOpts::default())
.map_err(|e| GDError::DnsResolve(e.to_string()))?;
let response = resolver.lookup_ip(address)
.map_err(|e| GDError::DnsResolve(e.to_string()))?;
Ok(response.iter().next().ok_or(GDError::DnsResolve("Couldn't resolve the DNS address.".to_string()))?.to_string())
}
pub fn error_by_expected_size(expected: usize, size: usize) -> GDResult<()> {
if size < expected {
Err(GDError::PacketUnderflow("Unexpectedly short packet.".to_string()))
@ -24,8 +12,8 @@ pub fn error_by_expected_size(expected: usize, size: usize) -> GDResult<()> {
}
}
pub fn complete_address(address: &str, port: u16) -> GDResult<String> {
Ok(resolve_dns(address)? + ":" + &*port.to_string())
pub fn address_and_port_as_string(address: &str, port: u16) -> GDResult<String> {
Ok(address.to_string() + ":" + &*port.to_string())
}
pub fn u8_lower_upper(n: u8) -> (u8, u8) {
@ -132,9 +120,9 @@ mod tests {
use super::*;
#[test]
fn complete_address_test() {
assert_eq!(complete_address("192.168.0.1", 27015).unwrap(), "192.168.0.1:27015");
assert!(complete_address("not_existent_address", 9999).is_err());
fn address_and_port_as_string_test() {
assert_eq!(address_and_port_as_string("192.168.0.1", 27015).unwrap(), "192.168.0.1:27015");
assert!(address_and_port_as_string("not_existent_address", 9999).is_err());
}
#[test]