aboutsummaryrefslogblamecommitdiff
path: root/src/hotstuff_app.cpp
blob: 768e81e796445f930d9f9310bff15a33f47145d8 (plain) (tree)






































                                      
                         


                            

                           




                                             

                                    
                           
                    
                                                              
                               
                                                                            
                        

                                                                      
                                            

                         
                                               
 
                                                          






                                                 




                                                        
                                                              
                          
                                 
                                                                     
      

     

                                  
                                   
                                       



                                               
                                              
                                        



                 





























                                                                               
                                                             

                                                            
                                                            



                                                                      


                                                                                                             
                                                            
                                                                                                             

                                                                                                               
                                                                                                                 

                                                                                    
                    
                          


































                                                                      


                                                    
                                                                                            

                                                                                        
            
                                                                                                
 
                                                   
                                                   
                                                   



                                                                   
                                              
                                






                                                                        
                          








                                                     
                                           
                                               



                                                       
                                                      
                                                
                                        
                                                 
                             
                                     

           
                                
                                                    
                                                                                                     
                            

 

                                                                           

                              
                               
                                                                   


                                                       

 
                           




                                                         
                                                








                                                                   

                                   
                  
 
#include <iostream>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <random>
#include <unistd.h>
#include <signal.h>
#include <event2/event.h>

#include "salticidae/stream.h"
#include "salticidae/util.h"
#include "salticidae/network.h"
#include "salticidae/msg.h"

#include "hotstuff/promise.hpp"
#include "hotstuff/type.h"
#include "hotstuff/entity.h"
#include "hotstuff/util.h"
#include "hotstuff/client.h"
#include "hotstuff/hotstuff.h"

using salticidae::MsgNetwork;
using salticidae::ClientNetwork;
using salticidae::ElapsedTime;
using salticidae::Config;
using salticidae::_1;
using salticidae::_2;
using salticidae::static_pointer_cast;
using salticidae::trim_all;
using salticidae::split;

using hotstuff::Event;
using hotstuff::EventContext;
using hotstuff::NetAddr;
using hotstuff::HotStuffError;
using hotstuff::CommandDummy;
using hotstuff::Finality;
using hotstuff::command_t;
using hotstuff::uint256_t;
using hotstuff::opcode_t;
using hotstuff::bytearray_t;
using hotstuff::DataStream;
using hotstuff::ReplicaID;
using hotstuff::MsgReqCmd;
using hotstuff::MsgRespCmd;
using hotstuff::get_hash;
using hotstuff::promise_t;

using HotStuff = hotstuff::HotStuffSecp256k1;

class HotStuffApp: public HotStuff {
    double stat_period;
    double impeach_timeout;
    EventContext ec;
    /** Network messaging between a replica and its client. */
    ClientNetwork<opcode_t> cn;
    /** Timer object to schedule a periodic printing of system statistics */
    Event ev_stat_timer;
    /** Timer object to monitor the progress for simple impeachment */
    Event impeach_timer;
    /** The listen address for client RPC */
    NetAddr clisten_addr;

    using Conn = ClientNetwork<opcode_t>::Conn;

    void client_request_cmd_handler(MsgReqCmd &&, Conn &);

    command_t parse_cmd(DataStream &s) override {
        au