mirror of
https://github.com/Cuprate/cuprate.git
synced 2024-12-22 19:49:28 +00:00
Wire: fix IPv4 Endianness (#342)
Some checks are pending
CI / fmt (push) Waiting to run
CI / typo (push) Waiting to run
CI / ci (macos-latest, stable, bash) (push) Waiting to run
CI / ci (ubuntu-latest, stable, bash) (push) Waiting to run
CI / ci (windows-latest, stable-x86_64-pc-windows-gnu, msys2 {0}) (push) Waiting to run
Doc / build (push) Waiting to run
Doc / deploy (push) Blocked by required conditions
Some checks are pending
CI / fmt (push) Waiting to run
CI / typo (push) Waiting to run
CI / ci (macos-latest, stable, bash) (push) Waiting to run
CI / ci (ubuntu-latest, stable, bash) (push) Waiting to run
CI / ci (windows-latest, stable-x86_64-pc-windows-gnu, msys2 {0}) (push) Waiting to run
Doc / build (push) Waiting to run
Doc / deploy (push) Blocked by required conditions
* fix IPv4 Endianness * fix import order
This commit is contained in:
parent
0f1ad6db1b
commit
241088e273
2 changed files with 12 additions and 6 deletions
|
@ -17,10 +17,12 @@
|
||||||
//! Monero network. Core Monero has 4 main addresses: IPv4, IPv6, Tor,
|
//! Monero network. Core Monero has 4 main addresses: IPv4, IPv6, Tor,
|
||||||
//! I2p. Currently this module only has IPv(4/6).
|
//! I2p. Currently this module only has IPv(4/6).
|
||||||
//!
|
//!
|
||||||
use bytes::BufMut;
|
|
||||||
use cuprate_epee_encoding::EpeeObject;
|
|
||||||
use std::{hash::Hash, net, net::SocketAddr};
|
use std::{hash::Hash, net, net::SocketAddr};
|
||||||
|
|
||||||
|
use bytes::BufMut;
|
||||||
|
|
||||||
|
use cuprate_epee_encoding::EpeeObject;
|
||||||
|
|
||||||
mod epee_builder;
|
mod epee_builder;
|
||||||
use epee_builder::*;
|
use epee_builder::*;
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
use bytes::Buf;
|
|
||||||
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
|
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
|
||||||
|
|
||||||
use cuprate_epee_encoding::{epee_object, EpeeObjectBuilder};
|
use bytes::Buf;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
|
use cuprate_epee_encoding::{epee_object, EpeeObjectBuilder};
|
||||||
|
|
||||||
use crate::NetworkAddress;
|
use crate::NetworkAddress;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
@ -77,7 +78,7 @@ impl From<NetworkAddress> for TaggedNetworkAddress {
|
||||||
SocketAddr::V4(addr) => Self {
|
SocketAddr::V4(addr) => Self {
|
||||||
ty: Some(1),
|
ty: Some(1),
|
||||||
addr: Some(AllFieldsNetworkAddress {
|
addr: Some(AllFieldsNetworkAddress {
|
||||||
m_ip: Some(u32::from_be_bytes(addr.ip().octets())),
|
m_ip: Some(u32::from_le_bytes(addr.ip().octets())),
|
||||||
m_port: Some(addr.port()),
|
m_port: Some(addr.port()),
|
||||||
addr: None,
|
addr: None,
|
||||||
}),
|
}),
|
||||||
|
@ -112,7 +113,10 @@ epee_object!(
|
||||||
impl AllFieldsNetworkAddress {
|
impl AllFieldsNetworkAddress {
|
||||||
fn try_into_network_address(self, ty: u8) -> Option<NetworkAddress> {
|
fn try_into_network_address(self, ty: u8) -> Option<NetworkAddress> {
|
||||||
Some(match ty {
|
Some(match ty {
|
||||||
1 => NetworkAddress::from(SocketAddrV4::new(Ipv4Addr::from(self.m_ip?), self.m_port?)),
|
1 => NetworkAddress::from(SocketAddrV4::new(
|
||||||
|
Ipv4Addr::from(self.m_ip?.to_le_bytes()),
|
||||||
|
self.m_port?,
|
||||||
|
)),
|
||||||
2 => NetworkAddress::from(SocketAddrV6::new(
|
2 => NetworkAddress::from(SocketAddrV6::new(
|
||||||
Ipv6Addr::from(self.addr?),
|
Ipv6Addr::from(self.addr?),
|
||||||
self.m_port?,
|
self.m_port?,
|
||||||
|
|
Loading…
Reference in a new issue