plebble
us::gov::id::peer_t Class Reference

#include <peer_t.h>

Inheritance diagram for us::gov::id::peer_t:
Collaboration diagram for us::gov::id::peer_t:

Classes

class  handshake_t
 
class  handshakes_t
 
enum  role_t
 
enum  stage_t
 

Public Types

enum  stage_t {
  anonymous =0, verified, verified_fail, num_stages,
  stage_t.anonymous = 0, stage_t.verified = 1, stage_t.verified_fail = 2, stage_t.num_stages = 3
}
 
enum  role_t { role_peer =0, role_sysop =1, role_device =2, num_roles }
 
enum  stage_t {
  anonymous =0, verified, verified_fail, num_stages,
  stage_t.anonymous = 0, stage_t.verified = 1, stage_t.verified_fail = 2, stage_t.num_stages = 3
}
 
typedef socket::peer_t b
 
typedef crypto::ec::keys keys
 
typedef keys::pub_t pub_t
 
typedef pub_t::hash_t hash_t
 
using datagram = socket::datagram
 
- Public Types inherited from us::gov::socket::peer_t
typedef client b
 
- Public Types inherited from us::gov::socket::client
enum  security_level_t { security_level_ok, security_level_disconnect, security_level_ban }
 
typedef us::gov::socket::send_queue_t queue_t
 

Public Member Functions

 peer_t (int sock)
 
virtual ~peer_t ()
 
ko connect (const string &host, uint16_t port, uint16_t pport, role_t, bool block)
 
virtual ko connect (uint32_t host, uint16_t port, uint16_t pport, role_t, bool block)
 
virtual void verification_completed (uint16_t rpport)
 
virtual const keysget_keys () const
 
virtual void dump_all (const string &prefix, ostream &os) const override
 
void dump (const string &prefix, ostream &os) const
 
bool process_work (datagram *d)
 
void process_request (datagram *d, const keys &)
 
void process_peer_challenge (datagram *d, const keys &)
 
void process_challenge_response (datagram *d)
 
ko initiate_dialogue (role_t role, uint16_t pport_pin)
 
bool verification_is_fine () const
 
string short_version () const
 
ko turn_on_encryption ()
 
ko wait_auth () const
 
pair< ko, datagram * > encrypt0 (datagram *) const override
 
pair< ko, datagram * > decrypt0 (datagram *) const override
 
void disconnect (uint16_t seq, const string &reason) override
 
stage_t get_stage_peer () const
 
void set_stage_peer (stage_t)
 
daemonget_parent ()
 
const daemonget_parent () const
 
bool is_role_peer () const
 
bool is_role_sysop () const
 
bool is_role_device () const
 
 peer_t (Socket sock)
 
String connect (String host, int port, char role, bool block)
 
override bool process_work (datagram d)
 
void process_request (datagram d, KeyPair mykeys)
 
void process_peer_challenge (datagram d, KeyPair mykeys)
 
void process_challenge_response (datagram d)
 
void initiate_dialogue (char role)
 
bool verification_is_fine ()
 
virtual void verification_completed ()
 
virtual KeyPair get_keys ()
 
String run_auth_responder ()
 
 peer_t (Socket sock)
 
ko connect (String host, uint16_t port, uint16_t pport_pin, role_t role, boolean block)
 
ko connect (String endpoint, uint16_t pport_pin, role_t role, boolean block)
 
boolean process_work (datagram d)
 
ko initiate_dialogue (role_t role, uint16_t pport)
 
void process_request (datagram d, KeyPair mykeys)
 
void process_peer_challenge (datagram d, KeyPair mykeys)
 
void process_challenge_response (datagram d)
 
ko turn_on_encryption ()
 
pair< ko, datagramencrypt0 (datagram d)
 
pair< ko, datagramdecrypt0 (datagram e)
 
boolean verification_is_fine ()
 
void verification_completed (uint16_t rpport)
 
KeyPair get_keys ()
 
ko wait_auth ()
 
- Public Member Functions inherited from us::gov::socket::peer_t
 peer_t ()
 
 peer_t (int sock)
 
 peer_t (const peer_t &)=delete
 
peer_toperator= (const peer_t &)=delete
 
 ~peer_t () override
 
void dump_all (const string &prefix, ostream &os) const override
 
pair< security_level_t, string > security_level () const override
 
bool stalled_datagram () const
 
bool process_work (datagram *d)
 
void dump (const string &prefix, ostream &os) const
 
virtual void on_peer_disconnected (const string &reason)
 
 peer_t ()
 
 peer_t (Socket sock)
 
bool is_slow ()
 
bool ping ()
 
void process_pong ()
 
 peer_t ()
 
void on_peer_disconnected (String reason)
 
- Public Member Functions inherited from us::gov::socket::client
 client ()
 
 client (int sock)
 
virtual ~client ()
 
ko connect0 (uint32_t host, uint16_t port, bool block)
 
ko connect0 (const string &host, uint16_t port, bool block)
 
bool connected () const
 
pair< uint32_t, uint16_t > raddress () const
 
virtual void on_connect (ko)
 
pair< ko, datagram * > recv4x (datagram *d)
 
pair< ko, datagram * > recv6 ()
 
ko init_sock2 (uint32_t host, uint16_t port, bool block)
 
void dump (const string &prefix, ostream &os) const
 
string refdata () const
 
string endpoint () const
 
virtual ko send1 (datagram *)
 
void prepare_worker_recv ()
 
void worker_ended_recv ()
 
void set_finished ()
 
bool is_finished () const
 
void test_alive ()
 
void ping ()
 
 client ()
 
 client (Socket sock_)
 
String connect0 (String host, int port)
 
String connect0 (String host, int port, bool block)
 
void disconnect ()
 
bool connected ()
 
bool IsConnected ()
 
String address ()
 
void ready ()
 
pair< String, datagramsend_recv3 (datagram d)
 
pair< String, datagramrecv6 ()
 
pair< String, datagramrecv3 ()
 
pair< String, datagramrecv4 (datagram d)
 
String send3 (datagram d)
 
 client ()
 
 client (Socket sock_)
 
void prepare_worker_recv ()
 
void worker_ended_recv ()
 
void on_connect (ko err)
 
ko connect0 (String host, uint16_t port)
 
ko connect0 (String host, uint16_t hport, boolean block)
 
void disconnect (uint16_t seq, String reason)
 
boolean connected ()
 
String address ()
 
String endpoint ()
 
pair< ko, datagramrecv6 ()
 
pair< ko, datagramrecv4x (datagram d)
 
boolean is_finished ()
 
void dump (String prefix, PrintStream os)
 
void test_alive ()
 
ko send1 (datagram d0)
 

Static Public Member Functions

static string to_string (const vector< unsigned char > &data)
 
static String get_random_message ()
 
- Static Public Member Functions inherited from us::gov::socket::client
static uint32_t host2addr (const string &host)
 
static string age (uint64_t msts)
 
static string age (chrono::system_clock::time_point time)
 
static string ip4_decode (uint32_t addr)
 
static uint32_t ip4_encode (const string &addr)
 
static bool is_wan_ip (uint32_t)
 
static bool is_valid_ip (uint32_t)
 
static string endpoint (uint32_t addr, uint16_t port)
 
static string endpoint (const pair< uint32_t, uint16_t > &ip)
 
static pair< ko, pair< string, uint16_t > > parse_endpoint (const string &ipport)
 
static pair< ko, pair< String, Short > > parse_endpoint (String ipport)
 
static String ip4_decode (uint32_t addr0)
 
static uint32_t ip4_encode (String addr0)
 
static String endpoint (uint32_t a, uint16_t p)
 
static String endpoint (String a, uint16_t p)
 

Public Attributes

stage_t stage_peer {anonymous}
 
handshakes_thandshakes {nullptr}
 
role_t role {role_peer}
 
pub_t pubkey
 
uint16_t version_fingerprint {0}
 
mutex mx_auth
 
condition_variable cv_auth
 
crypto::symmetric_encryptionse {nullptr}
 
byte[] pubkey
 
PublicKey pubkey =null
 
- Public Attributes inherited from us::gov::socket::peer_t
datagramcurd {nullptr}
 
mutex mx_curd
 
- Public Attributes inherited from us::gov::socket::client
chrono::system_clock::time_point since
 
chrono::system_clock::time_point activity_recv
 
chrono::system_clock::time_point last_test_alive
 
atomic< uint64_t > activity
 
atomic< int > busyrecv {0}
 
int sock =null
 
uint32_t address
 
uint16_t port
 
atomic< int > sendref {0}
 
serverparent {nullptr}
 
queue_tsendq {nullptr}
 
pair< uint16_t, string > finished_reason
 
atomic< bool > finished {false}
 
Socket sock =null
 
long since
 
send_queue sendq =null
 
AtomicInteger sendref =new AtomicInteger(0)
 
long uid =++prev_uid
 

Static Public Attributes

static const char * KO_6017
 
constexpr static array< const char *, num_stagesstagestr ={"anonymous","verified","verified_fail"}
 
constexpr static array< const char *, num_rolesrolestr ={"peer","sysop","device"}
 
static ko KO_6017 =new ko("KO 6017 authentication failed.")
 
static final String[] stagestr = {"anonymous","verified","verified_fail"}
 
static final ko KO_43823 =new ko("KO 43823 Invalid endpoint")
 
- Static Public Attributes inherited from us::gov::socket::peer_t
constexpr static chrono::seconds stall {5s}
 
static const char * finished_reason_1
 
static const char * finished_reason_2
 
- Static Public Attributes inherited from us::gov::socket::client
static const char * KO_7190
 
static const char * KO_58961
 
static const char * KO_60541
 
static const char * KO_10100
 
static const char * KO_20190
 
static const char * KO_20191
 
static busyled_t busyled_recv =new busyled_t()
 
static struct timeval timeout
 
static final ko KO_58961 =new ko("KO 58961 Invalid port.")
 
static final ko KO_83911 =new ko("KO 83911 IO Exception.")
 
static final ko KO_83912 =new ko("KO 83912 Exception.")
 
static final ko KO_10100 =new ko("KO 10100 Unreachable host.")
 
static final ko KO_20190 =new ko("KO 20190 Invalid endpoint port.")
 
static final ko KO_20191 =new ko("KO 20191 Invalid endpoint host.")
 
static long prev_uid =0
 

Package Functions

boolean is_role_peer ()
 
boolean is_role_sysop ()
 
boolean is_role_device ()
 
void set_stage_peer (stage_t s)
 
stage_t get_stage_peer ()
 
String short_version ()
 
- Package Functions inherited from us::gov::socket::client
String refdata ()
 
void set_finished ()
 

Package Attributes

uint16_t daemon_pport =uint16_t.zero
 
handshakes_t handshakes =null
 
ReentrantLock mx_auth = new ReentrantLock()
 
Condition cv_auth =mx_auth.newCondition()
 
symmetric_encryption se =null
 
- Package Attributes inherited from us::gov::socket::client
pair< uint16_t, String > finished_reason =new pair<uint16_t, String>(new uint16_t(0), "")
 
AtomicBoolean finished =new AtomicBoolean(false)
 
AtomicInteger busyrecv =new AtomicInteger(0)
 
boolean called_disconnect =false
 
long activity_recv
 
long last_test_alive
 
AtomicLong activity =new AtomicLong(0L)
 

Private Attributes

String msg
 

Member Typedef Documentation

◆ b

◆ datagram

◆ hash_t

◆ keys

◆ pub_t

Member Enumeration Documentation

◆ role_t

Enumerator
role_peer 
role_sysop 
role_device 
num_roles 

◆ stage_t [1/2]

Enumerator
anonymous 
verified 
verified_fail 
num_stages 
anonymous 
verified 
verified_fail 
num_stages 

◆ stage_t [2/2]

Enumerator
anonymous 
verified 
verified_fail 
num_stages 
anonymous 
verified 
verified_fail 
num_stages 

Constructor & Destructor Documentation

◆ peer_t() [1/3]

us::gov::id::peer_t::peer_t ( int  sock)

◆ ~peer_t()

virtual us::gov::id::peer_t::~peer_t ( )
virtual

◆ peer_t() [2/3]

us.gov.id.peer_t.peer_t ( Socket  sock)
inline

Reimplemented from us::gov::socket::peer_t.

◆ peer_t() [3/3]

us.gov.id.peer_t.peer_t ( Socket  sock)
inline

Member Function Documentation

◆ connect() [1/5]

ko us::gov::id::peer_t::connect ( const string &  host,
uint16_t  port,
uint16_t  pport,
role_t  ,
bool  block 
)

Referenced by connect(), and us.wallet.rpc_api::connect_walletd().

Here is the caller graph for this function:

◆ connect() [2/5]

ko us.gov.id.peer_t.connect ( String  endpoint,
uint16_t  pport_pin,
role_t  role,
boolean  block 
)
inline

◆ connect() [3/5]

String us.gov.id.peer_t.connect ( String  host,
int  port,
char  role,
bool  block 
)
inline

References initiate_dialogue(), us::gov::socket::client.port, and role.

Here is the call graph for this function:

◆ connect() [4/5]

ko us.gov.id.peer_t.connect ( String  host,
uint16_t  port,
uint16_t  pport_pin,
role_t  role,
boolean  block 
)
inline

References initiate_dialogue(), us.ko.is_ok(), us::gov::socket::client.port, and role.

Here is the call graph for this function:

◆ connect() [5/5]

virtual ko us::gov::id::peer_t::connect ( uint32_t  host,
uint16_t  port,
uint16_t  pport,
role_t  ,
bool  block 
)
virtual

◆ decrypt0() [1/2]

pair<ko, datagram*> us::gov::id::peer_t::decrypt0 ( datagram ) const
overridevirtual

Reimplemented from us::gov::socket::client.

◆ decrypt0() [2/2]

pair<ko, datagram> us.gov.id.peer_t.decrypt0 ( datagram  e)
inline

Reimplemented from us::gov::socket::client.

References us::gov::socket::datagram.decrypt(), us.ok, se, and us::gov::socket::datagram.service.

Here is the call graph for this function:

◆ disconnect()

void us::gov::id::peer_t::disconnect ( uint16_t  seq,
const string &  reason 
)
overridevirtual

Reimplemented from us::gov::socket::client.

Reimplemented in us::gov::peer::peer_t.

◆ dump()

void us::gov::id::peer_t::dump ( const string &  prefix,
ostream &  os 
) const

◆ dump_all()

virtual void us::gov::id::peer_t::dump_all ( const string &  prefix,
ostream &  os 
) const
overridevirtual

◆ encrypt0() [1/2]

pair<ko, datagram*> us::gov::id::peer_t::encrypt0 ( datagram ) const
overridevirtual

Reimplemented from us::gov::socket::client.

◆ encrypt0() [2/2]

◆ get_keys() [1/3]

virtual KeyPair us.gov.id.peer_t.get_keys ( )
inlinevirtual

Reimplemented in us::gov::cli::rpc_api, and us.wallet.rpc_api.

◆ get_keys() [2/3]

KeyPair us.gov.id.peer_t.get_keys ( )
inline

Reimplemented in us::gov::cli::rpc_api, and us.wallet.rpc_api.

◆ get_keys() [3/3]

virtual const keys& us::gov::id::peer_t::get_keys ( ) const
virtual

Reimplemented in test_client, us::gov::engine::peer_t, and us::gov::cli::rpc_api.

Referenced by process_work(), and turn_on_encryption().

Here is the caller graph for this function:

◆ get_parent() [1/2]

daemon* us::gov::id::peer_t::get_parent ( )

◆ get_parent() [2/2]

const daemon* us::gov::id::peer_t::get_parent ( ) const

◆ get_random_message()

static String us.gov.id.peer_t.get_random_message ( )
inlinestatic

References us.gov.crypto.base58.encode().

Referenced by initiate_dialogue(), and process_request().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_stage_peer() [1/2]

stage_t us.gov.id.peer_t.get_stage_peer ( )
inlinepackage

References mx_auth, and stage_peer.

◆ get_stage_peer() [2/2]

stage_t us::gov::id::peer_t::get_stage_peer ( ) const

Referenced by turn_on_encryption(), and verification_is_fine().

Here is the caller graph for this function:

◆ initiate_dialogue() [1/3]

void us.gov.id.peer_t.initiate_dialogue ( char  role)
inline

References get_random_message(), us.gov.protocol.gov_id_request, msg, role, and us::gov::socket::client.send3().

Here is the call graph for this function:

◆ initiate_dialogue() [2/3]

◆ initiate_dialogue() [3/3]

ko us::gov::id::peer_t::initiate_dialogue ( role_t  role,
uint16_t  pport_pin 
)

Referenced by connect().

Here is the caller graph for this function:

◆ is_role_device() [1/2]

boolean us.gov.id.peer_t.is_role_device ( )
inlinepackage

◆ is_role_device() [2/2]

bool us::gov::id::peer_t::is_role_device ( ) const
inline

◆ is_role_peer() [1/2]

boolean us.gov.id.peer_t.is_role_peer ( )
inlinepackage

◆ is_role_peer() [2/2]

bool us::gov::id::peer_t::is_role_peer ( ) const
inline

◆ is_role_sysop() [1/2]

boolean us.gov.id.peer_t.is_role_sysop ( )
inlinepackage

◆ is_role_sysop() [2/2]

bool us::gov::id::peer_t::is_role_sysop ( ) const
inline

◆ process_challenge_response() [1/3]

void us::gov::id::peer_t::process_challenge_response ( datagram d)

Referenced by process_work().

Here is the caller graph for this function:

◆ process_challenge_response() [2/3]

◆ process_challenge_response() [3/3]

◆ process_peer_challenge() [1/3]

void us::gov::id::peer_t::process_peer_challenge ( datagram d,
const keys  
)

Referenced by process_work().

Here is the caller graph for this function:

◆ process_peer_challenge() [2/3]

◆ process_peer_challenge() [3/3]

◆ process_request() [1/3]

void us::gov::id::peer_t::process_request ( datagram d,
const keys  
)

Referenced by process_work().

Here is the caller graph for this function:

◆ process_request() [2/3]

◆ process_request() [3/3]

◆ process_work() [1/3]

bool us::gov::id::peer_t::process_work ( datagram d)

Referenced by run_auth_responder().

Here is the caller graph for this function:

◆ process_work() [2/3]

◆ process_work() [3/3]

◆ run_auth_responder()

String us.gov.id.peer_t.run_auth_responder ( )
inline

◆ set_stage_peer() [1/2]

void us.gov.id.peer_t.set_stage_peer ( stage_t  s)
inlinepackage

References mx_auth, and stage_peer.

◆ set_stage_peer() [2/2]

void us::gov::id::peer_t::set_stage_peer ( stage_t  )

Referenced by initiate_dialogue(), process_challenge_response(), process_peer_challenge(), and process_request().

Here is the caller graph for this function:

◆ short_version() [1/2]

String us.gov.id.peer_t.short_version ( )
inlinepackage

References us.gov.crypto.base58.encode(), and version_fingerprint.

Here is the call graph for this function:

◆ short_version() [2/2]

string us::gov::id::peer_t::short_version ( ) const

◆ to_string()

static string us::gov::id::peer_t::to_string ( const vector< unsigned char > &  data)
static

◆ turn_on_encryption() [1/2]

ko us::gov::id::peer_t::turn_on_encryption ( )

Referenced by process_challenge_response(), and process_peer_challenge().

Here is the caller graph for this function:

◆ turn_on_encryption() [2/2]

ko us.gov.id.peer_t.turn_on_encryption ( )
inline

◆ verification_completed() [1/3]

virtual void us.gov.id.peer_t.verification_completed ( )
inlinevirtual

Reimplemented in us::gov::auth::peer_t.

Referenced by process_challenge_response(), and process_peer_challenge().

Here is the caller graph for this function:

◆ verification_completed() [2/3]

virtual void us::gov::id::peer_t::verification_completed ( uint16_t  rpport)
inlinevirtual

◆ verification_completed() [3/3]

void us.gov.id.peer_t.verification_completed ( uint16_t  rpport)
inline

◆ verification_is_fine() [1/3]

bool us.gov.id.peer_t.verification_is_fine ( )
inline

◆ verification_is_fine() [2/3]

boolean us.gov.id.peer_t.verification_is_fine ( )
inline

References get_stage_peer(), and us.gov.id.peer_t.stage_t.verified.

Here is the call graph for this function:

◆ verification_is_fine() [3/3]

bool us::gov::id::peer_t::verification_is_fine ( ) const
inline

◆ wait_auth() [1/2]

◆ wait_auth() [2/2]

ko us::gov::id::peer_t::wait_auth ( ) const

Referenced by us::gov::cli::rpc_api::send1(), and us.wallet.daemon.rpc_api::wait_auth().

Here is the caller graph for this function:

Member Data Documentation

◆ cv_auth [1/2]

condition_variable us::gov::id::peer_t::cv_auth
mutable

◆ cv_auth [2/2]

Condition us.gov.id.peer_t.cv_auth =mx_auth.newCondition()
package

◆ daemon_pport

uint16_t us.gov.id.peer_t.daemon_pport =uint16_t.zero
package

Referenced by process_request().

◆ handshakes [1/2]

handshakes_t* us::gov::id::peer_t::handshakes {nullptr}

◆ handshakes [2/2]

handshakes_t us.gov.id.peer_t.handshakes =null
package

◆ KO_43823

final ko us.gov.id.peer_t.KO_43823 =new ko("KO 43823 Invalid endpoint")
static

Referenced by connect().

◆ KO_6017 [1/2]

const char* us::gov::id::peer_t::KO_6017
static

Referenced by wait_auth().

◆ KO_6017 [2/2]

ko us.gov.id.peer_t.KO_6017 =new ko("KO 6017 authentication failed.")
static

◆ msg

◆ mx_auth [1/2]

mutex us::gov::id::peer_t::mx_auth
mutable

◆ mx_auth [2/2]

ReentrantLock us.gov.id.peer_t.mx_auth = new ReentrantLock()
package

◆ pubkey [1/3]

◆ pubkey [2/3]

byte [] us.gov.id.peer_t.pubkey

◆ pubkey [3/3]

PublicKey us.gov.id.peer_t.pubkey =null

◆ role

◆ rolestr

constexpr static array<const char*,num_roles> us::gov::id::peer_t::rolestr ={"peer","sysop","device"}
staticconstexpr

◆ se [1/2]

crypto::symmetric_encryption* us::gov::id::peer_t::se {nullptr}
mutable

◆ se [2/2]

symmetric_encryption us.gov.id.peer_t.se =null
package

◆ stage_peer

◆ stagestr [1/2]

constexpr static array<const char*,num_stages> us::gov::id::peer_t::stagestr ={"anonymous","verified","verified_fail"}
staticconstexpr

◆ stagestr [2/2]

final String [] us.gov.id.peer_t.stagestr = {"anonymous","verified","verified_fail"}
static

◆ version_fingerprint

uint16_t us::gov::id::peer_t::version_fingerprint {0}

The documentation for this class was generated from the following files: