aboutsummaryrefslogblamecommitdiff
path: root/test_p2p_stress/main.go
blob: 095dc561e30575a81f2af9751eb0c1d474b2f67c (plain) (tree)
1
2
3
4
5
6
7
8
9
10

            
                      
                      

                                  
                                


                                                            
                                                        
                                                                




                                              
                                

                                                                                    



                        


          






                                              

 
       

                                                

 
                                                                                   













                                                                                                     

 
                                                                                    






                                                                         

 
                                                                           






                                                                                  

 
                                                                                   





                                                                    

 
                                        



                                                                                                

 
                         





                                                       


                        




                                     

 
                               




                                                            

 
                                   
                                                  


                                              
                                                                    

 
                                                                 






                                           

 
                                                                                           



                                                    



                          

                              
                


                                                         











                                                                                         


                      
                                                                                               







                                                                                 



                                                                                                     













                                                                                   
 



                                                     
 


                                       
 






















                                                                                                                            

 

                                                                                                 












                                                                                            

 
                     
                                                                                                       





                                                                                                                     

 

                                                                    


                                      


               
                                        







                                                                    


             

                                         
 

































                                                                                                              
 



















                                                           
 



                                                                                         
 
                     
 
package main

// #include <stdlib.h>
// #include <stdint.h>
// #include <arpa/inet.h>
// #include "salticidae/network.h"
// void onTerm(int sig, void *);
// void onReceiveRand(msg_t *, msgnetwork_conn_t *, void *);
// void onReceiveAck(msg_t *, msgnetwork_conn_t *, void *);
// void onStopLoop(threadcall_handle_t *, void *);
// void peerHandler(peernetwork_conn_t *, bool, void *);
// void errorHandler(SalticidaeCError *, bool, int32_t, void *);
// void onTimeout(timerev_t *, void *);
// typedef struct timeout_callback_context_t {
//     int app_id;
//     uint64_t addr_id;
//     msgnetwork_conn_t *conn;
// } timeout_callback_context_t;
// static timeout_callback_context_t *timeout_callback_context_new() {
//     timeout_callback_context_t *ctx = malloc(sizeof(timeout_callback_context_t));
//     ctx->conn = NULL;
//     return ctx;
// }
//
import "C"

import (
	"fmt"
	"github.com/Determinant/salticidae-go"
	"math/rand"
	"os"
	"strconv"
	"sync"
	"unsafe"
)

const (
	MSG_OPCODE_RAND salticidae.Opcode = iota
	MSG_OPCODE_ACK
)

func msgRandSerialize(view uint32, size int) (salticidae.Msg, salticidae.UInt256) {
	serialized := salticidae.NewDataStream(false)
	defer serialized.Free()
	serialized.PutU32(salticidae.ToLittleEndianU32(view))
	buffer := make([]byte, size)
	_, err := rand.Read(buffer)
	if err != nil {
		panic("rand source failed")
	}
	serialized.PutData(buffer)
	ba := salticidae.NewByteArrayFromBytes(buffer, false)
	defer ba.Free()
	payload := salticidae.NewByteArrayMovedFromDataStream(serialized, false)
	defer payload.Free()
	return salticidae.NewMsgMovedFromByteArray(MSG_OPCODE_RAND, payload, false), ba.