plebble
trader_protocol.h
Go to the documentation of this file.
1 /*
2 -------------------------------------------------------------------------------
3  PLEBBLE
4 -------------------------------------------------------------------------------
5  Copyright (C) 2019-2020 KATLAS Technology. (http://katlastechnology.com)
6  Copyright (C) 2017-2020 Marcos Mayorga. (mm@mm-studios.com)
7 
8  This file is part of our Plebble(R) Platform.
9 
10  The code below cannot be copied, used for any purpose other than the one
11  agreed and/or distributed without the express permission of
12  KATLAS Technology.
13 -------------------------------------------------------------------------------
14 
15 
16 */
17 #ifndef USGOV_9f682ad6777265e421626b7224642bd05ecd82b2c28599ed688342f9568a68c6
18 #define USGOV_9f682ad6777265e421626b7224642bd05ecd82b2c28599ed688342f9568a68c6
19 
21 #include <us/gov/crypto/ec.h>
22 #include <us/gov/socket/datagram.h>
23 #include <us/gov/socket/client.h>
24 #include <utility>
25 #include <thread>
26 #include <vector>
27 #include <mutex>
28 #include <atomic>
29 #include <condition_variable>
30 #include <fstream>
31 #include <sstream>
32 
33 namespace us{ namespace wallet {
34  using namespace std;
37  struct peer_t;
38  struct wallet_local_api;
40  using namespace us::gov;
41 
42  struct trader;
43  struct wallet_daemon;
44 
45  struct trader_protocol {
46  trader_protocol(const string&home);
47  virtual ~trader_protocol();
48  virtual void dump(ostream&) const;
49  void help(ostream&) const;
50  virtual void help_online(ostream&) const;
51  virtual void help_onoffline(ostream&) const;
52  virtual void data(ostream&) const;
53  virtual void api_list(ostream&) const;
54  virtual const char* get_name() const=0;
55  virtual const char* rolestr() const=0;
56  virtual const char* peer_rolestr() const=0;
57  virtual bool process_work(socket::client *c, unsigned char code, const string& data);
58  virtual bool process_work(socket::client *c, unsigned char code, const vector<unsigned char>& data);
59  virtual bool exec(socket::client*, const string& cmd, istream&, ostream& os);
60  bool exec_offline(socket::client* c, const string& cmd0, istream& is, ostream& os);
61  bool exec_online(socket::client* c, const string& cmd0, istream& is, ostream& os);
62  virtual bool requires_online(const string& cmd) const;
63  virtual string AI_chat(socket::client *c, unsigned char code);
64  string my_personality_str() const;
65  string peer_personality_str() const;
66 
67  void to_stream(ostream&) const;
68  static trader_protocol* from_stream(istream&);
69 
71  keys k;
72 
73  string invoice;
74  string transaction;
75  string tx;
76  ostream* tradelog{0};
77 
78 
79  hash_t peer_personality{0};
80  vector<unsigned char> image;
81 
82  struct chat_entry: string {
84  chat_entry(const string& s):string(s) {}
85  bool me;
86 
87  };
88  struct chat_t:vector<chat_entry> {
89  void dump(int max, ostream&) const;
90  };
91 
93 
94  vector<pair<string,string>> redirects;
95 
96  string phome;
97  string ihome;
98  trader* tder{0};
99  };
100 
101 }}
102 
103 #endif
104 
us::wallet::hash_t
us::gov::crypto::ripemd160::value_type hash_t
Definition: trader.h:38
us::wallet::trader_protocol::help
void help(ostream &) const
us::wallet::trader_protocol::process_work
virtual bool process_work(socket::client *c, unsigned char code, const vector< unsigned char > &data)
us::wallet::trader_protocol::my_personality
hash_t my_personality() const
us::wallet::trader_protocol::~trader_protocol
virtual ~trader_protocol()
us::wallet::trader_protocol::dump
virtual void dump(ostream &) const
us::gov::socket::client
Definition: client.h:44
us::wallet::trader_protocol
Definition: trader_protocol.h:45
us::wallet::trader_protocol::get_name
virtual const char * get_name() const =0
us::wallet::trader_protocol::tx
string tx
Definition: trader_protocol.h:75
us::wallet::trader_protocol::requires_online
virtual bool requires_online(const string &cmd) const
us::gov::dfs::peer_t
relay::peer_t peer_t
Definition: daemon.h:31
us
Definition: daemon.h:22
us::gov::crypto::ripemd160::value_type
Definition: ripemd160.h:38
us::wallet::trader_protocol::phome
string phome
Definition: trader_protocol.h:96
us::wallet::trader_protocol::chat_entry::chat_entry
chat_entry()
Definition: trader_protocol.h:83
us::wallet::trader_protocol::ihome
string ihome
Definition: trader_protocol.h:97
us::wallet::trader_protocol::exec
virtual bool exec(socket::client *, const string &cmd, istream &, ostream &os)
us::wallet::trader_protocol::chat_entry
Definition: trader_protocol.h:82
us::wallet::trader_protocol::k
keys k
Definition: trader_protocol.h:71
us::wallet::trader_protocol::to_stream
void to_stream(ostream &) const
us::gov::socket::datagram
Definition: datagram.h:44
us::gov::crypto::ripemd160.hash_t
Definition: ripemd160.java:25
us::wallet::trader_protocol::help_online
virtual void help_online(ostream &) const
us::wallet::trader_protocol::transaction
string transaction
Definition: trader_protocol.h:74
us::wallet::trader_protocol::redirects
vector< pair< string, string > > redirects
Definition: trader_protocol.h:94
us::wallet::trader_protocol::my_personality_str
string my_personality_str() const
us::wallet::trader_protocol::AI_chat
virtual string AI_chat(socket::client *c, unsigned char code)
us::wallet::trader_protocol::from_stream
static trader_protocol * from_stream(istream &)
us::wallet::trader_protocol::process_work
virtual bool process_work(socket::client *c, unsigned char code, const string &data)
us::wallet::trader_protocol::help_onoffline
virtual void help_onoffline(ostream &) const
us::wallet::trader_protocol::chat
chat_t chat
Definition: trader_protocol.h:92
us::wallet::trader_protocol::chat_t::dump
void dump(int max, ostream &) const
us::wallet::trader_protocol::image
vector< unsigned char > image
Definition: trader_protocol.h:80
us::wallet::trader_protocol::exec_offline
bool exec_offline(socket::client *c, const string &cmd0, istream &is, ostream &os)
us::gov
Definition: daemon.h:22
us::wallet::trader_protocol::rolestr
virtual const char * rolestr() const =0
us::wallet::trader_protocol::exec_online
bool exec_online(socket::client *c, const string &cmd0, istream &is, ostream &os)
datagram.h
ripemd160.h
c
Definition: client.cpp:417
us::wallet::trader_protocol::chat_t
Definition: trader_protocol.h:88
us::wallet::trader
Definition: trader.h:47
std
Definition: app.h:380
us::wallet::trader_protocol::api_list
virtual void api_list(ostream &) const
us::wallet::trader_protocol::chat_entry::chat_entry
chat_entry(const string &s)
Definition: trader_protocol.h:84
us::gov::crypto::ec::keys
Definition: ec.h:43
us::wallet::trader_protocol::chat_entry::me
bool me
Definition: trader_protocol.h:85
us::wallet::trader_protocol::data
virtual void data(ostream &) const
us::wallet::trader_protocol::peer_personality_str
string peer_personality_str() const
us::wallet::trader_protocol::trader_protocol
trader_protocol(const string &home)
ec.h
us::wallet::trader_protocol::invoice
string invoice
Definition: trader_protocol.h:73
client.h
us::wallet::keys
us::gov::crypto::ec::keys keys
Definition: trader.h:36
us::wallet::trader_protocol::peer_rolestr
virtual const char * peer_rolestr() const =0