Permalink
Browse files

Get rid of the binding code, except for the basic class which we're s…

…till using for File/Pid watch. no more binding bag.
  • Loading branch information...
1 parent dc3e84b commit 2b05a1230075a69fc0d54487617c15ca562cefe7 @jakedouglas jakedouglas committed Oct 28, 2009
Showing with 10 additions and 136 deletions.
  1. +2 −88 ext/binder.cpp
  2. +0 −5 ext/binder.h
  3. +3 −32 ext/ed.cpp
  4. +0 −3 ext/ed.h
  5. +0 −1 ext/project.h
  6. +4 −6 ext/ssl.cpp
  7. +1 −1 ext/ssl.h
View
@@ -19,107 +19,21 @@ See the file COPYING for complete licensing information.
#include "project.h"
-#define DEV_URANDOM "/dev/urandom"
-
-
-map<unsigned long, Bindable_t*> Bindable_t::BindingBag;
-
-
-/********************************
-STATIC Bindable_t::CreateBinding
-********************************/
-
-unsigned long Bindable_t::CreateBinding()
-{
- // XXX use atomic_t to prevent thread-safety issues
- static unsigned long num = 0;
- while(BindingBag[++num]);
- return num;
-}
-
-#if 0
-string Bindable_t::CreateBinding()
-{
- static int index = 0;
- static string seed;
-
- if ((index >= 1000000) || (seed.length() == 0)) {
- #ifdef OS_UNIX
- int fd = open (DEV_URANDOM, O_RDONLY);
- if (fd < 0)
- throw std::runtime_error ("No entropy device");
-
- unsigned char u[16];
- size_t r = read (fd, u, sizeof(u));
- if (r < sizeof(u))
- throw std::runtime_error ("Unable to read entropy device");
-
- unsigned char *u1 = (unsigned char*)u;
- char u2 [sizeof(u) * 2 + 1];
-
- for (size_t i=0; i < sizeof(u); i++)
- sprintf (u2 + (i * 2), "%02x", u1[i]);
-
- seed = string (u2);
- #endif
-
-
- #ifdef OS_WIN32
- UUID uuid;
- UuidCreate (&uuid);
- unsigned char *uuidstring = NULL;
- UuidToString (&uuid, &uuidstring);
- if (!uuidstring)
- throw std::runtime_error ("Unable to read uuid");
- seed = string ((const char*)uuidstring);
-
- RpcStringFree (&uuidstring);
- #endif
-
- index = 0;
-
-
- }
-
- stringstream ss;
- ss << seed << (++index);
- return ss.str();
-}
-#endif
-
-/*****************************
-STATIC: Bindable_t::GetObject
-*****************************/
-
-Bindable_t *Bindable_t::GetObject (const unsigned long binding)
-{
- map<unsigned long, Bindable_t*>::const_iterator i = BindingBag.find (binding);
- if (i != BindingBag.end())
- return i->second;
- else
- return NULL;
-}
-
/**********************
Bindable_t::Bindable_t
**********************/
-Bindable_t::Bindable_t()
+Bindable_t::Bindable_t():
+ Binding(NULL)
{
- Binding = Bindable_t::CreateBinding();
- BindingBag [Binding] = this;
}
-
/***********************
Bindable_t::~Bindable_t
***********************/
Bindable_t::~Bindable_t()
{
- BindingBag.erase (Binding);
}
-
-
View
@@ -24,11 +24,6 @@ See the file COPYING for complete licensing information.
class Bindable_t
{
public:
- static unsigned long CreateBinding();
- static Bindable_t *GetObject (const unsigned long);
- static map<unsigned long, Bindable_t*> BindingBag;
-
- public:
Bindable_t();
virtual ~Bindable_t();
View
@@ -301,32 +301,6 @@ ConnectionDescriptor::~ConnectionDescriptor()
#endif
}
-/*********************************************
-STATIC: ConnectionDescriptor::CloseConnection
-*********************************************/
-
-void ConnectionDescriptor::CloseConnection (const unsigned long binding, bool after_writing)
-{
- // TODO: This is something of a hack, or at least it's a static method of the wrong class.
- EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
- if (ed)
- ed->ScheduleClose (after_writing);
-}
-
-/***********************************************
-STATIC: ConnectionDescriptor::ReportErrorStatus
-***********************************************/
-
-int ConnectionDescriptor::ReportErrorStatus (const unsigned long binding)
-{
- // TODO: This is something of a hack, or at least it's a static method of the wrong class.
- // TODO: Poor polymorphism here. We should be calling one virtual method
- // instead of hacking out the runtime information of the target object.
- ConnectionDescriptor *cd = dynamic_cast <ConnectionDescriptor*> (Bindable_t::GetObject (binding));
- if (cd)
- return cd->_ReportErrorStatus();
- return -1;
-}
/***********************************
ConnectionDescriptor::_UpdateEvents
@@ -994,7 +968,7 @@ void ConnectionDescriptor::StartTls()
if (SslBox)
throw std::runtime_error ("SSL/TLS already running on connection");
- SslBox = new SslBox_t (bIsServer, PrivateKeyFilename, CertChainFilename, bSslVerifyPeer, GetBinding());
+ SslBox = new SslBox_t (bIsServer, PrivateKeyFilename, CertChainFilename, bSslVerifyPeer, this);
_DispatchCiphertext();
#endif
@@ -1657,11 +1631,8 @@ STATIC: DatagramDescriptor::SendDatagram
int DatagramDescriptor::SendDatagram (const unsigned long binding, const char *data, int length, const char *address, int port)
{
- DatagramDescriptor *dd = dynamic_cast <DatagramDescriptor*> (Bindable_t::GetObject (binding));
- if (dd)
- return dd->SendOutboundDatagram (data, length, address, port);
- else
- return -1;
+ // this is blank because we got rid of GetObject. This shouldn't have been static anyway. wtf?
+ return -1;
}
View
@@ -146,9 +146,6 @@ class ConnectionDescriptor: public EventableDescriptor
ConnectionDescriptor (int, EventMachine_t*);
virtual ~ConnectionDescriptor();
- static void CloseConnection (const unsigned long, bool);
- static int ReportErrorStatus (const unsigned long);
-
int SendOutboundData (const char*, int);
void SetConnectPending (bool f);
View
@@ -132,7 +132,6 @@ static inline int inotify_rm_watch (int fd, __u32 wd) { return syscall (__NR_ino
#include "binder.h"
#include "em.h"
-#include "epoll.h"
#include "sigs.h"
#include "ed.h"
#include "files.h"
View
@@ -208,7 +208,7 @@ SslContext_t::~SslContext_t()
SslBox_t::SslBox_t
******************/
-SslBox_t::SslBox_t (bool is_server, const string &privkeyfile, const string &certchainfile, bool verify_peer, const unsigned long binding):
+SslBox_t::SslBox_t (bool is_server, const string &privkeyfile, const string &certchainfile, bool verify_peer, ConnectionDescriptor *cd):
bIsServer (is_server),
bHandshakeCompleted (false),
bVerifyPeer (verify_peer),
@@ -233,8 +233,8 @@ SslBox_t::SslBox_t (bool is_server, const string &privkeyfile, const string &cer
assert (pSSL);
SSL_set_bio (pSSL, pbioRead, pbioWrite);
- // Store a pointer to the binding signature in the SSL object so we can retrieve it later
- SSL_set_ex_data(pSSL, 0, (void*) binding);
+ // Store a pointer to ConnectionDescriptor in the SSL object so we can retrieve it later
+ SSL_set_ex_data(pSSL, 0, (void*) cd);
if (bVerifyPeer)
SSL_set_verify(pSSL, SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE, ssl_verify_wrapper);
@@ -433,7 +433,6 @@ ssl_verify_wrapper
extern "C" int ssl_verify_wrapper(int preverify_ok, X509_STORE_CTX *ctx)
{
- unsigned long binding;
X509 *cert;
SSL *ssl;
BUF_MEM *buf;
@@ -442,14 +441,13 @@ extern "C" int ssl_verify_wrapper(int preverify_ok, X509_STORE_CTX *ctx)
cert = X509_STORE_CTX_get_current_cert(ctx);
ssl = (SSL*) X509_STORE_CTX_get_ex_data(ctx, SSL_get_ex_data_X509_STORE_CTX_idx());
- binding = (unsigned long) SSL_get_ex_data(ssl, 0);
+ ConnectionDescriptor *cd = (ConnectionDescriptor*) SSL_get_ex_data(ssl, 0);
out = BIO_new(BIO_s_mem());
PEM_write_bio_X509(out, cert);
BIO_write(out, "\0", 1);
BIO_get_mem_ptr(out, &buf);
- ConnectionDescriptor *cd = dynamic_cast <ConnectionDescriptor*> (Bindable_t::GetObject(binding));
result = (cd->VerifySslPeer(buf->data) == true ? 1 : 0);
BUF_MEM_free(buf);
View
@@ -57,7 +57,7 @@ class SslBox_t
class SslBox_t
{
public:
- SslBox_t (bool is_server, const string &privkeyfile, const string &certchainfile, bool verify_peer, const unsigned long binding);
+ SslBox_t (bool is_server, const string &privkeyfile, const string &certchainfile, bool verify_peer, ConnectionDescriptor*);
virtual ~SslBox_t();
int PutPlaintext (const char*, int);

0 comments on commit 2b05a12

Please sign in to comment.