Skip to content

Commit 2f5ce0b

Browse files
committedJun 24, 2020
Add default port for peers
1 parent 6b30f9e commit 2f5ce0b

File tree

5 files changed

+11
-5
lines changed

5 files changed

+11
-5
lines changed
 

‎CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ This project follows [semantic versioning](http://semver.org).
66
### UNRELEASED
77

88
- [added] Added crypto option AES128
9+
- [added] Default port for peers
910
- [changed] Updated dependencies
1011
- [fixed] Fixed keepalive for small timeouts
1112

12-
1313
### v1.4.0 (2020-06-03)
1414

1515
- [added] Added option to listen on specified IP

‎rustfmt.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ wrap_comments = true
1414
overflow_delimited_expr = true
1515
blank_lines_upper_bound = 2
1616
normalize_doc_attributes = true
17-
inline_attribute_width = 50
17+
inline_attribute_width = 50
18+
edition = "2018"
19+
reorder_impl_items = true

‎src/cloud.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rand::{prelude::*, random, thread_rng};
1919

2020
use super::{
2121
beacon::BeaconSerializer,
22-
config::{Config, DEFAULT_PEER_TIMEOUT},
22+
config::{Config, DEFAULT_PEER_TIMEOUT, DEFAULT_PORT},
2323
crypto::Crypto,
2424
device::Device,
2525
net::Socket,
@@ -364,8 +364,11 @@ impl<D: Device, P: Protocol, T: Table, S: Socket, TS: TimeSource> GenericCloud<D
364364
///
365365
/// This method adds a peer to the list of nodes to reconnect to. A periodic task will try to
366366
/// connect to the peer if it is not already connected.
367-
pub fn add_reconnect_peer(&mut self, add: String) {
367+
pub fn add_reconnect_peer(&mut self, mut add: String) {
368368
let now = TS::now();
369+
if add.find(':').unwrap_or(0) <= add.find(']').unwrap_or(0) { // : not present or only in IPv6 address
370+
add = format!("{}:{}", add, DEFAULT_PORT)
371+
}
369372
let resolved = match resolve(&add as &str) {
370373
Ok(addrs) => addrs,
371374
Err(err) => {

‎src/config.rs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use std::{
2121

2222
const HASH_PREFIX: &str = "hash:";
2323
pub const DEFAULT_PEER_TIMEOUT: u16 = 600;
24+
pub const DEFAULT_PORT: u16 = 3210;
2425

2526

2627
fn parse_listen(addr: &str) -> SocketAddr {

‎src/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ fn address_decode_encode() {
293293
assert_eq!(&buf[0..7], &[6, 0x78, 0x2d, 0x16, 0x05, 0x01, 0x02]);
294294
assert_eq!((addr, 7), Address::read_from(&buf).unwrap());
295295
assert_eq!(addr, Address::read_from_fixed(&buf[1..], 6).unwrap());
296-
assert!(Address::read_from(&buf[0..0]).is_err()); // Address too short
296+
assert!(Address::read_from(&buf[0..1]).is_err()); // Address too short
297297
buf[0] = 100;
298298
assert!(Address::read_from(&buf).is_err()); // Invalid address, too long
299299
buf[0] = 5;

0 commit comments

Comments
 (0)
Please sign in to comment.