1
1
use crate :: { Enr , EnrError , EnrKey , EnrPublicKey , Key , NodeId , MAX_ENR_SIZE } ;
2
2
use bytes:: { Bytes , BytesMut } ;
3
3
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
+ } ;
5
9
6
10
///! The base builder for generating ENR records with arbitrary signing algorithms.
7
11
pub struct EnrBuilder < K : EnrKey > {
@@ -49,16 +53,23 @@ impl<K: EnrKey> EnrBuilder<K> {
49
53
self
50
54
}
51
55
52
- /// Adds an `ip` field to the `ENRBuilder`.
56
+ /// Adds an `ip`/`ip6` field to the `ENRBuilder`.
53
57
pub fn ip ( & mut self , ip : IpAddr ) -> & mut Self {
54
58
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) ,
61
61
}
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 ( ) ) ;
62
73
self
63
74
}
64
75
@@ -74,7 +85,7 @@ impl<K: EnrKey> EnrBuilder<K> {
74
85
*/
75
86
76
87
/// 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 {
78
89
self . add_value ( "tcp" , & tcp. to_be_bytes ( ) ) ;
79
90
self
80
91
}
@@ -86,7 +97,7 @@ impl<K: EnrKey> EnrBuilder<K> {
86
97
}
87
98
88
99
/// 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 {
90
101
self . add_value ( "udp" , & udp. to_be_bytes ( ) ) ;
91
102
self
92
103
}
0 commit comments