fix server port allocation
This commit is contained in:
parent
79bf6fca69
commit
559ac5f162
@ -164,9 +164,9 @@ impl Network {
|
|||||||
|
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
|
|
||||||
fn find_available_udp_port(&self) -> EyreResult<u16> {
|
fn find_available_udp_port(&self, start_port: u16) -> EyreResult<u16> {
|
||||||
// If the address is empty, iterate ports until we find one we can use.
|
// If the address is empty, iterate ports until we find one we can use.
|
||||||
let mut udp_port = 5150u16;
|
let mut udp_port = start_port;
|
||||||
loop {
|
loop {
|
||||||
if BAD_PORTS.contains(&udp_port) {
|
if BAD_PORTS.contains(&udp_port) {
|
||||||
continue;
|
continue;
|
||||||
@ -182,9 +182,9 @@ impl Network {
|
|||||||
Ok(udp_port)
|
Ok(udp_port)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_available_tcp_port(&self) -> EyreResult<u16> {
|
fn find_available_tcp_port(&self, start_port: u16) -> EyreResult<u16> {
|
||||||
// If the address is empty, iterate ports until we find one we can use.
|
// If the address is empty, iterate ports until we find one we can use.
|
||||||
let mut tcp_port = 5150u16;
|
let mut tcp_port = start_port;
|
||||||
loop {
|
loop {
|
||||||
if BAD_PORTS.contains(&tcp_port) {
|
if BAD_PORTS.contains(&tcp_port) {
|
||||||
continue;
|
continue;
|
||||||
@ -203,7 +203,7 @@ impl Network {
|
|||||||
async fn allocate_udp_port(&self, listen_address: String) -> EyreResult<(u16, Vec<IpAddr>)> {
|
async fn allocate_udp_port(&self, listen_address: String) -> EyreResult<(u16, Vec<IpAddr>)> {
|
||||||
if listen_address.is_empty() {
|
if listen_address.is_empty() {
|
||||||
// If listen address is empty, find us a port iteratively
|
// If listen address is empty, find us a port iteratively
|
||||||
let port = self.find_available_udp_port()?;
|
let port = self.find_available_udp_port(5150)?;
|
||||||
let ip_addrs = vec![
|
let ip_addrs = vec![
|
||||||
IpAddr::V4(Ipv4Addr::UNSPECIFIED),
|
IpAddr::V4(Ipv4Addr::UNSPECIFIED),
|
||||||
IpAddr::V6(Ipv6Addr::UNSPECIFIED),
|
IpAddr::V6(Ipv6Addr::UNSPECIFIED),
|
||||||
@ -218,9 +218,7 @@ impl Network {
|
|||||||
bail!("No valid listen address: {}", listen_address);
|
bail!("No valid listen address: {}", listen_address);
|
||||||
}
|
}
|
||||||
let port = sockaddrs[0].port();
|
let port = sockaddrs[0].port();
|
||||||
if !self.bind_first_udp_port(port) {
|
|
||||||
bail!("Could not find free udp port to listen on");
|
|
||||||
}
|
|
||||||
Ok((port, sockaddrs.iter().map(|s| s.ip()).collect()))
|
Ok((port, sockaddrs.iter().map(|s| s.ip()).collect()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -228,7 +226,7 @@ impl Network {
|
|||||||
async fn allocate_tcp_port(&self, listen_address: String) -> EyreResult<(u16, Vec<IpAddr>)> {
|
async fn allocate_tcp_port(&self, listen_address: String) -> EyreResult<(u16, Vec<IpAddr>)> {
|
||||||
if listen_address.is_empty() {
|
if listen_address.is_empty() {
|
||||||
// If listen address is empty, find us a port iteratively
|
// If listen address is empty, find us a port iteratively
|
||||||
let port = self.find_available_tcp_port()?;
|
let port = self.find_available_tcp_port(5150)?;
|
||||||
let ip_addrs = vec![
|
let ip_addrs = vec![
|
||||||
IpAddr::V4(Ipv4Addr::UNSPECIFIED),
|
IpAddr::V4(Ipv4Addr::UNSPECIFIED),
|
||||||
IpAddr::V6(Ipv6Addr::UNSPECIFIED),
|
IpAddr::V6(Ipv6Addr::UNSPECIFIED),
|
||||||
|
@ -120,38 +120,38 @@ core:
|
|||||||
application:
|
application:
|
||||||
https:
|
https:
|
||||||
enabled: false
|
enabled: false
|
||||||
listen_address: ':5150'
|
listen_address: ':443'
|
||||||
path: 'app'
|
path: 'app'
|
||||||
# url: 'https://localhost:5150'
|
# url: 'https://localhost'
|
||||||
http:
|
http:
|
||||||
enabled: false
|
enabled: false
|
||||||
listen_address: ':5150'
|
listen_address: ':80'
|
||||||
path: 'app'
|
path: 'app'
|
||||||
# url: 'http://localhost:5150'
|
# url: 'http://localhost'
|
||||||
protocol:
|
protocol:
|
||||||
udp:
|
udp:
|
||||||
enabled: true
|
enabled: true
|
||||||
socket_pool_size: 0
|
socket_pool_size: 0
|
||||||
listen_address: ':5150'
|
listen_address: ''
|
||||||
# public_address: ''
|
# public_address: ''
|
||||||
tcp:
|
tcp:
|
||||||
connect: true
|
connect: true
|
||||||
listen: true
|
listen: true
|
||||||
max_connections: 32
|
max_connections: 32
|
||||||
listen_address: ':5150'
|
listen_address: ''
|
||||||
#'public_address: ''
|
#'public_address: ''
|
||||||
ws:
|
ws:
|
||||||
connect: true
|
connect: true
|
||||||
listen: true
|
listen: true
|
||||||
max_connections: 16
|
max_connections: 16
|
||||||
listen_address: ':5150'
|
listen_address: ''
|
||||||
path: 'ws'
|
path: 'ws'
|
||||||
# url: 'ws://localhost:5150/ws'
|
# url: 'ws://localhost:5150/ws'
|
||||||
wss:
|
wss:
|
||||||
connect: true
|
connect: true
|
||||||
listen: false
|
listen: false
|
||||||
max_connections: 16
|
max_connections: 16
|
||||||
listen_address: ':5150'
|
listen_address: ''
|
||||||
path: 'ws'
|
path: 'ws'
|
||||||
# url: ''
|
# url: ''
|
||||||
"#,
|
"#,
|
||||||
@ -351,6 +351,12 @@ pub struct NamedSocketAddrs {
|
|||||||
impl FromStr for NamedSocketAddrs {
|
impl FromStr for NamedSocketAddrs {
|
||||||
type Err = std::io::Error;
|
type Err = std::io::Error;
|
||||||
fn from_str(s: &str) -> Result<NamedSocketAddrs, std::io::Error> {
|
fn from_str(s: &str) -> Result<NamedSocketAddrs, std::io::Error> {
|
||||||
|
if s.is_empty() {
|
||||||
|
return Ok(NamedSocketAddrs {
|
||||||
|
name: String::new(),
|
||||||
|
addrs: vec![],
|
||||||
|
});
|
||||||
|
}
|
||||||
let addr_iter = listen_address_to_socket_addrs(s)
|
let addr_iter = listen_address_to_socket_addrs(s)
|
||||||
.map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidInput, e))?;
|
.map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidInput, e))?;
|
||||||
Ok(NamedSocketAddrs {
|
Ok(NamedSocketAddrs {
|
||||||
|
Loading…
Reference in New Issue
Block a user