Skip to content
This repository was archived by the owner on Nov 20, 2023. It is now read-only.

Commit b5e31ff

Browse files
change method return types and names to better differentiate Ip versions (#33)
* clearly differentiate ip4 and ip6 fields * clearly differentiate ip4 and ip6 fields in builder * fix tests * fix release tests * update set methods * print ipv6 socket addr * bump minor version
1 parent 80b3ca8 commit b5e31ff

File tree

3 files changed

+89
-74
lines changed

3 files changed

+89
-74
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "enr"
33
authors = ["Age Manning <[email protected]>"]
44
edition = "2018"
5-
version = "0.5.1"
5+
version = "0.6.0"
66
description = "Rust implementation of Ethereum Node Record (ENR) EIP778"
77
readme = "./README.md"
88
keywords = ["ethereum", "enr", "record", "EIP778", "node"]

src/builder.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
use crate::{Enr, EnrError, EnrKey, EnrPublicKey, Key, NodeId, MAX_ENR_SIZE};
22
use bytes::{Bytes, BytesMut};
33
use rlp::RlpStream;
4-
use std::{collections::BTreeMap, marker::PhantomData, net::IpAddr};
4+
use std::{
5+
collections::BTreeMap,
6+
marker::PhantomData,
7+
net::{IpAddr, Ipv4Addr, Ipv6Addr},
8+
};
59

610
///! The base builder for generating ENR records with arbitrary signing algorithms.
711
pub struct EnrBuilder<K: EnrKey> {
@@ -49,16 +53,23 @@ impl<K: EnrKey> EnrBuilder<K> {
4953
self
5054
}
5155

52-
/// Adds an `ip` field to the `ENRBuilder`.
56+
/// Adds an `ip`/`ip6` field to the `ENRBuilder`.
5357
pub fn ip(&mut self, ip: IpAddr) -> &mut Self {
5458
match ip {
55-
IpAddr::V4(addr) => {
56-
self.add_value("ip", &addr.octets());
57-
}
58-
IpAddr::V6(addr) => {
59-
self.add_value("ip6", &addr.octets());
60-
}
59+
IpAddr::V4(addr) => self.ip4(addr),
60+
IpAddr::V6(addr) => self.ip6(addr),
6161
}
62+
}
63+
64+
/// Adds an `ip` field to the `ENRBuilder`.
65+
pub fn ip4(&mut self, ip: Ipv4Addr) -> &mut Self {
66+
self.add_value("ip", &ip.octets());
67+
self
68+
}
69+
70+
/// Adds an `ip6` field to the `ENRBuilder`.
71+
pub fn ip6(&mut self, ip: Ipv6Addr) -> &mut Self {
72+
self.add_value("ip6", &ip.octets());
6273
self
6374
}
6475

@@ -74,7 +85,7 @@ impl<K: EnrKey> EnrBuilder<K> {
7485
*/
7586

7687
/// Adds a `tcp` field to the `ENRBuilder`.
77-
pub fn tcp(&mut self, tcp: u16) -> &mut Self {
88+
pub fn tcp4(&mut self, tcp: u16) -> &mut Self {
7889
self.add_value("tcp", &tcp.to_be_bytes());
7990
self
8091
}
@@ -86,7 +97,7 @@ impl<K: EnrKey> EnrBuilder<K> {
8697
}
8798

8899
/// Adds a `udp` field to the `ENRBuilder`.
89-
pub fn udp(&mut self, udp: u16) -> &mut Self {
100+
pub fn udp4(&mut self, udp: u16) -> &mut Self {
90101
self.add_value("udp", &udp.to_be_bytes());
91102
self
92103
}

0 commit comments

Comments
 (0)