aboutsummaryrefslogblamecommitdiff
path: root/src/hotstuff_client.cpp
blob: e8d7b9e7219831de3021565219509ca8f3b86522 (plain) (tree)
1
2
3
4
5
6
7
8
9
                  
                 
                   

                     



                               



                            
 
                         
 
                          

                             

                           

                             
                              
                          
                         
                          
 
                
                   

                     

                 
                 



                  
                     
                               
                                                 
                                                        

  


                                                 
                                                     
                              
                                                       
                          
 




                                                                 
                                  
                   


                                                                       

 
                 

                                                          
                                                
                                                            
                            
                                                        
                                 

                                                              
      
                                      
                                                      




                             
                                                                     
                        
                                                               
                                             
                                     


                                    
















                                                                       
                                                                          




                                                            


                                                          
      
                      
               


                                                                               
                                                               


                                          

                                   
 
                                                
                                                       

                                                           
                                                 
 





                                                  
                                            



































                                                                                      
 
                                





                                                                                          
     
      

             
#include <cassert>
#include <random>
#include <signal.h>
#include <sys/time.h>

#include "salticidae/type.h"
#include "salticidae/netaddr.h"
#include "salticidae/network.h"
#include "salticidae/util.h"

#include "hotstuff/util.h"
#include "hotstuff/type.h"
#include "hotstuff/client.h"

using salticidae::Config;

using hotstuff::ReplicaID;
using hotstuff::NetAddr;
using hotstuff::EventContext;
using hotstuff::MsgReqCmd;
using hotstuff::MsgRespCmd;
using hotstuff::CommandDummy;
using hotstuff::Finality;
using hotstuff::HotStuffError;
using hotstuff::uint256_t;
using hotstuff::opcode_t;
using hotstuff::command_t;

EventContext ec;
ReplicaID proposer;
size_t max_async_num;
int max_iter_num;
uint32_t cid;
uint32_t cnt = 0;
uint32_t nfaulty;

struct Request {
    ReplicaID rid;
    command_t cmd;
    size_t confirmed;
    salticidae::ElapsedTime et;
    Request(ReplicaID rid, const command_t &cmd):
        rid(rid), cmd(cmd), confirmed(0) { et.start(); }
};

using Net = salticidae::MsgNetwork<opcode_t>;

std::unordered_map<ReplicaID, Net::conn_t> conns;
std::unordered_map<const uint256_t, Request> waiting;
std::vector<NetAddr> replicas;
std::vector<std::pair<struct timeval, double>> elapsed;
Net mn(ec, Net::Config());

void connect_all() {
    for (size_t i = 0; i < replicas.size(); i++)
        conns.insert(std::make_pair(i, mn.connect(replicas[i])));
}

void set_proposer(ReplicaID rid) {
    proposer = rid;
//    auto it = conns.find(rid);
//    if (it == conns.end())
//        conns.insert(std::make_pair(rid, mn.connect(replicas[rid])));
}

void try_send() {
    while (waiting.size() < max_async_num && max_iter_num)
    {
        auto cmd = new CommandDummy(cid, cnt++);
        //mn.send_msg(MsgReqCmd(*cmd), *conns.at(proposer));
        MsgReqCmd msg(*cmd);
        for (auto &p: conns) mn.send_msg(msg, p.second);
#ifndef HOTSTUFF_ENABLE_BENCHMARK
        HOTSTUFF_LOG_INFO("send new cmd %.10s",
                            get_hex(cmd->get_hash()).c_str());
#endif
        waiting.