Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
ip.hpp
Go to the documentation of this file.
1#pragma once
2#include <fc/string.hpp>
3#include <fc/crypto/sha1.hpp>
4#include <fc/io/raw_fwd.hpp>
5#include <fc/crypto/city.hpp>
7
8namespace fc {
9
10 namespace ip {
11 class address {
12 public:
13 address( uint32_t _ip = 0 );
14 address( const fc::string& s );
15
16 address& operator=( const fc::string& s );
17 operator fc::string()const;
18 operator uint32_t()const;
19
20 friend bool operator==( const address& a, const address& b );
21 friend bool operator!=( const address& a, const address& b );
22
32 bool is_private_address()const;
36 bool is_multicast_address()const;
37
39 bool is_public_address()const;
40 private:
41 uint32_t _ip;
42 };
43
44 class endpoint {
45 public:
46 endpoint();
47 endpoint( const address& i, uint16_t p = 0);
48
50 static endpoint from_string( const string& s );
52 operator string()const;
53
54 void set_port(uint16_t p ) { _port = p; }
55 uint16_t port()const;
56 const address& get_address()const;
57
58 friend bool operator==( const endpoint& a, const endpoint& b );
59 friend bool operator!=( const endpoint& a, const endpoint& b );
60 friend bool operator< ( const endpoint& a, const endpoint& b );
61
62 private:
70 uint32_t _port;
71 address _ip;
72 };
73
74 }
75 class variant;
76 void to_variant( const ip::endpoint& var, variant& vo );
77 void from_variant( const variant& var, ip::endpoint& vo );
78
79 void to_variant( const ip::address& var, variant& vo );
80 void from_variant( const variant& var, ip::address& vo );
81
82
83 namespace raw
84 {
85 template<typename Stream>
86 inline void pack( Stream& s, const ip::address& v )
87 {
89 }
90 template<typename Stream>
91 inline void unpack( Stream& s, ip::address& v )
92 {
93 uint32_t _ip;
94 fc::raw::unpack( s, _ip );
95 v = ip::address(_ip);
96 }
97
98 template<typename Stream>
99 inline void pack( Stream& s, const ip::endpoint& v )
100 {
102 fc::raw::pack( s, v.port() );
103 }
104 template<typename Stream>
105 inline void unpack( Stream& s, ip::endpoint& v )
106 {
108 uint16_t p;
109 fc::raw::unpack( s, a );
110 fc::raw::unpack( s, p );
111 v = ip::endpoint(a,p);
112 }
113
114 }
115} // namespace fc
118namespace std
119{
120 template<>
121 struct hash<fc::ip::endpoint>
122 {
123 size_t operator()( const fc::ip::endpoint& e )const
124 {
125 return fc::city_hash_size_t( (char*)&e, sizeof(e) );
126 }
127 };
128}
const mie::Vuint & p
Definition bn.cpp:27
address & operator=(const fc::string &s)
Definition ip.cpp:29
bool is_private_address() const
Definition ip.cpp:105
bool is_public_address() const
Definition ip.cpp:133
friend bool operator!=(const address &a, const address &b)
Definition ip.cpp:25
bool is_multicast_address() const
Definition ip.cpp:125
friend bool operator==(const address &a, const address &b)
Definition ip.cpp:22
address(uint32_t _ip=0)
Definition ip.cpp:10
friend bool operator!=(const endpoint &a, const endpoint &b)
Definition ip.cpp:60
void set_port(uint16_t p)
Definition ip.hpp:54
const address & get_address() const
Definition ip.cpp:72
static endpoint from_string(const string &s)
Definition ip.cpp:74
friend bool operator<(const endpoint &a, const endpoint &b)
Definition ip.cpp:64
uint16_t port() const
Definition ip.cpp:71
friend bool operator==(const endpoint &a, const endpoint &b)
Definition ip.cpp:57
Concept for reading and writing characters.
void unpack(Stream &s, std::deque< T > &value)
Definition raw.hpp:540
void pack(Stream &s, const std::deque< T > &value)
Definition raw.hpp:531
namespace sysio::chain
Definition authority.cpp:3
std::string string
Definition string.hpp:10
size_t city_hash_size_t(const char *buf, size_t len)
Definition city.hpp:62
void from_variant(const fc::variant &v, sysio::chain::chain_id_type &cid)
void to_variant(const sysio::chain::shared_public_key &var, fc::variant &vo)
Definition authority.cpp:4
Definition name.hpp:106
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
#define FC_REFLECT_TYPENAME(TYPE)
Definition reflect.hpp:320
unsigned short uint16_t
Definition stdint.h:125
unsigned int uint32_t
Definition stdint.h:126
size_t operator()(const fc::ip::endpoint &e) const
Definition ip.hpp:123
char * s