mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 03:21:08 +03:00
Preventing save of loopback IPs, fix #236
This commit is contained in:
parent
15705b3fa1
commit
8f78b74d67
1 changed files with 10 additions and 5 deletions
|
@ -94,6 +94,11 @@ impl PeerStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn save_peer(&self, p: &PeerData) -> Result<(), Error> {
|
pub fn save_peer(&self, p: &PeerData) -> Result<(), Error> {
|
||||||
|
// we want to ignore any peer without a well-defined ip
|
||||||
|
let ip = p.addr.ip();
|
||||||
|
if ip.is_unspecified() || ip.is_loopback() {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
self.db.put_ser(
|
self.db.put_ser(
|
||||||
&to_key(PEER_PREFIX, &mut format!("{}", p.addr).into_bytes())[..],
|
&to_key(PEER_PREFIX, &mut format!("{}", p.addr).into_bytes())[..],
|
||||||
p,
|
p,
|
||||||
|
@ -133,11 +138,11 @@ impl PeerStore {
|
||||||
pub fn all_peers(&self) -> Vec<PeerData> {
|
pub fn all_peers(&self) -> Vec<PeerData> {
|
||||||
let peers_iter = self.db
|
let peers_iter = self.db
|
||||||
.iter::<PeerData>(&to_key(PEER_PREFIX, &mut "".to_string().into_bytes()));
|
.iter::<PeerData>(&to_key(PEER_PREFIX, &mut "".to_string().into_bytes()));
|
||||||
let mut peers = vec![];
|
let mut peers = vec![];
|
||||||
for p in peers_iter {
|
for p in peers_iter {
|
||||||
peers.push(p);
|
peers.push(p);
|
||||||
}
|
}
|
||||||
peers
|
peers
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience method to load a peer data, update its status and save it
|
/// Convenience method to load a peer data, update its status and save it
|
||||||
|
|
Loading…
Reference in a new issue