int main(int argc, char** argv) { publishService(&serv2_server_side); int fd; fd=connect_server("./socket"); UnixIO* io=new UnixIO(fd); ConnectionRef conn; conn=newConnection(io); if(conn.get()==NULL) return -1; bool b; b=requestService(conn, &serv1_client_side); if(!b) return -2; Register(); sleep(1); int i; int iloc=1; int irpc=1; for(i=0;i<10000;i++) { Add(irpc,3,irpc); iloc=iloc*3; if(irpc!=iloc) return -3; } return 0; }
int main(int argc, char** argv) { int fd; fd=connect_server("./socket"); UnixIO* io=new UnixIO(fd); ConnectionRef conn; conn=newConnection(io); if(conn.get()==NULL) return -1; bool b; b=requestService(conn, &serv1_client_side); if(!b) return -2; b=requestService(conn, &serv2_client_side); if(!b) return -3; int i; int iloc=0; int irpc=0; for(i=0;i<1000;i++) { Add(irpc,3,irpc); Mult(irpc,5,irpc); iloc=iloc+3; iloc=iloc*5; if(irpc!=iloc) return -4; } return 0; }
void Component::setConnection(const GarbledCircuit_BON::GarbledCircuit& gc) { //internal? std::set<InternalWire> iw = gc->getInternalWire(); for(auto iwIt=iw.begin(); iwIt!=iw.end(); iwIt++) { std::string srcPort = (*iwIt)->getSourcePortIndex(); std::string destPort = (*iwIt)->getDestinationPortIndex(); ConnectionRef srcCCR = (*iwIt)->getSrc(); ConnectionRef destCCR = (*iwIt)->getDst(); CodeGeneratorNameSpace::Connection conn(srcCCR->getComponent(srcPort), destCCR->getComponent(destPort)); conn.setDescription((*iwIt)->getDescription()); currentJC.insert(conn); } }
void Component::setInputOutput(const GarbledCircuit_BON::GarbledCircuit& gc) { //generator? std::set<DefineInOutPut> gtc = gc->getDefineInOutPut(); for(auto gtcIt=gtc.begin(); gtcIt!=gtc.end(); gtcIt++) { std::string srcPort = (*gtcIt)->getSourcePortIndex(); std::string destPort = (*gtcIt)->getDestinationPortIndex(); GarbledCircuit_BON::InOutPut cd = (*gtcIt)->getSrc(); ConnectionRef ccr = (*gtcIt)->getDst(); std::string inputname = cd->getObjectMeta().name(); if("Input" == inputname) { CodeGeneratorNameSpace::InputConnection ic(((GarbledCircuit_BON::Input)cd)->getPortStartIndex(), srcPort, ccr->getComponent(destPort)); ic.setDescription((*gtcIt)->getDescription()); currentJC.insert(ic); } //output else { CodeGeneratorNameSpace::OutputConnection ic(((GarbledCircuit_BON::Output)cd)->getPortStartIndex(), srcPort, ccr->getComponent(destPort)); ic.setDescription((*gtcIt)->getDescription()); currentJC.insert(ic); } } }
TLSSocket::TLSSocket(ConnectionRef sock){ this->sock=sock; SOCKET sockfd= ((Socket *)(sock.get()))->getSocket(); /*sslClient=new yaSSL::Client(); //sslClient->SetCA("E:\\bombus-ng\\certs\\class3.crt"); sslClient->SetCA("E:\\bombus-ng\\certs\\root.der"); int result=sslClient->Connect(sockfd);*/ SSLeay_add_ssl_algorithms(); SSL_load_error_strings(); SSL_METHOD* method=TLSv1_client_method(); SSL_CTX* ctx=SSL_CTX_new(method); this->ctx=ctx; SSL* ssl=SSL_new(ctx); this->ssl=ssl; int crt_result=SSL_CTX_use_certificate_file(ctx, "E:\\bombus-ng\\certs\\class3.crt", SSL_FILETYPE_PEM); SSL_set_fd(ssl, sockfd); int result=SSL_connect(ssl); int err=SSL_get_error(ssl, 0); int err2=SSL_get_error(ssl, err); //printf ("SSL connection using %s\n", SSL_get_cipher (ssl)); X509* server_cert= SSL_get_peer_certificate (ssl); char * str = X509_NAME_oneline (X509_get_subject_name (server_cert),0,0); //printf ("Server certificate:\n"); //printf ("\t subject: %s\n", str); OPENSSL_free (str); str = X509_NAME_oneline (X509_get_issuer_name (server_cert),0,0); //printf ("\t issuer: %s\n", str); OPENSSL_free (str); // We could do all sorts of certificate verification stuff here before //deallocating the certificate. X509_free (server_cert); }
TEST(SignalTest, ConnectionOwn) { unsigned counter = 0; auto f = [&counter]() { ++counter; }; Signal<> sig; ConnectionRef c0; { ConnectionRef tmp = sig.connect(f); tmp.own(); c0 = tmp; ASSERT_TRUE(tmp.isOwning()); ASSERT_FALSE(c0.isOwning()); sig(); ASSERT_EQ(1, counter); } ASSERT_TRUE(c0.isValid()); ASSERT_FALSE(c0.isConnected()); sig(); ASSERT_EQ(1, counter); }
static void ConnectionGotData( CFSocketRef s, CFSocketCallBackType type, CFDataRef address, const void * data, void * info ) // This is a a CFSocket callback indicating that data has arrived on the // socket. It's only called if the user has registered the associated // connection for listening. The parameter are as per the CFSocket // documentation. As this is a callback of type kCFSocketDataCallBack, // data contains newly arrived data that CFSocket has already read for us. { #pragma unused(address) CFDataRef newData; ConnectionRef conn; assert(s != NULL); assert(type == kCFSocketDataCallBack); // Cast data to a CFDataRef, newData. newData = (CFDataRef) data; assert(newData != NULL); assert( CFGetTypeID(newData) == CFDataGetTypeID() ); // Cast info to a ConnectionRef. conn = (ConnectionRef) info; assert(conn->fMagic == kConnectionStateMagic); if ( CFDataGetLength(newData) == 0 ) { // End of data stream; the server is dead. fprintf(stderr, "ConnectionGotData: Server died unexpectedly.\n"); // Tell the client. (void) conn->fCallback(conn, NULL, conn->fCallbackRefCon); // Shut 'er down Clancy, she's pumping mud! ConnectionShutdown(conn); } else { // We have new data from the server. Appending to our buffer. CFDataAppendBytes(conn->fBufferedPackets, CFDataGetBytePtr(newData), CFDataGetLength(newData)); // Now see if there are any complete packets in the buffer; and, // if so, deliver them to the client. do { PacketHeader * thisPacket; Boolean success; if ( CFDataGetLength(conn->fBufferedPackets) < sizeof(PacketHeader) ) { // Not enough data for the packet header; we're done. break; } thisPacket = (PacketHeader *) CFDataGetBytePtr(conn->fBufferedPackets); if ( thisPacket->fMagic != kPacketMagic ) { fprintf(stderr, "ConnectionGotData: Server sent us a packet with bad magic (%.4s).\n", (char *) &thisPacket->fMagic); ConnectionShutdown(conn); break; } if (thisPacket->fSize > kPacketMaximumSize) { fprintf(stderr, "ConnectionGotData: Server sent us a packet that's just too big (%" PRIu32 ").\n", thisPacket->fSize); ConnectionShutdown(conn); break; } if ( CFDataGetLength(conn->fBufferedPackets) < thisPacket->fSize ) { // Not enough data for the packet body; we're done. break; } // Tell the client about the packet. success = conn->fCallback(conn, thisPacket, conn->fCallbackRefCon); if ( ! success ) { ConnectionShutdown(conn); break; } // Delete this packet from the front of our packet buffer. I horror at // the inefficiency of this, but it is sample code after all. CFDataDeleteBytes(conn->fBufferedPackets, CFRangeMake(0, thisPacket->fSize)); } while (true); } }
TEST(SignalTest, ConnectionRef) { ConnectionRef ref; ASSERT_FALSE(ref.isValid()); ASSERT_FALSE(ref.isConnected()); }