Esempio n. 1
0
 def generate_reply(self, returned=None, optional=None):
   """This function is a bit crazy as it is entered from several points as both a callback or called directly :(
   returns either the successful msg, containing the symmertric key, balance, bank ip address, and login token
   OR
   the timeout until the client can log in again
   @param optional: text to return to the client with a code
   @type optional: [int, str]
   @return: None"""
   PROTOCOL = 1
   if self.successful:
     log_msg('Login was successful.', 3)
     EventLogging.save_event(BankLogin(username=self.username))
     #address of the bank server
     address = addressBook[0]
     curExp, nextExp = BankUtil.get_interval_time_deltas()
     format = '!BBIIII4sI'
     reply = struct.pack(format, PROTOCOL, 1, self.balance, Globals.CURRENT_ACOIN_INTERVAL[0], \
                                 curExp, nextExp, 
                                 inet_aton(address.host), address.port)
     reply += self.authBlob
   else:
     reply = struct.pack('!BBI', PROTOCOL, 0, self.timeout)
   #currently, 1 will replace the txt for a failure displayed client side, while 1 adds to it- thats all for now
   optional = [0, 'hello']
   if optional:
     code = struct.pack('!B', optional[0])
     reply += code + optional[1]
   #shove off the reply  
   self.reply(reply)
Esempio n. 2
0
 def _on_finished(self, results):
     """Everything worked (well enough).
 Log the event and return the SUCCESS code reply"""
     EventLogging.save_event(
         AccountCreated(hexkey=self.hexKey,
                        username=self.username,
                        mailinglist=self.shouldAddToMailingList))
     self._reply(RESPONSE_CODES["SUCCESS"])
Esempio n. 3
0
def reduce_size(data, amount):
  keys = data.keys()
  count = 0
  for key in keys:
    del data[key]
    count += 1
    if count >= amount:
      return

emails = {}
for i in range(0,40):
  emails["*****@*****.**"%(random_hex(10))] = random_hex(20)

for email, ref in emails.iteritems():
  EventLogging.save_event(Events.EmailSent(address=email, hexkey=ref))
reduce_size(emails, 5)

for email, ref in emails.iteritems():
  EventLogging.save_event(Events.EmailOpened(hexkey=ref))
  EventLogging.save_event(Events.EmailOpened(hexkey=ref))
reduce_size(emails, 5)

for email, ref in emails.iteritems():
  EventLogging.save_event(Events.EmailLinkVisit(hexkey=ref))
  EventLogging.save_event(Events.EmailLinkVisit(hexkey=ref))
reduce_size(emails, 5)

users = {}
for email, ref in emails.iteritems():
  username = random_hex(8)
Esempio n. 4
0
 def _on_finished(self, results):
   """Everything worked (well enough).
   Log the event and return the SUCCESS code reply"""
   EventLogging.save_event(AccountCreated(hexkey=self.hexKey, username=self.username, mailinglist=self.shouldAddToMailingList))
   self._reply(RESPONSE_CODES["SUCCESS"])
Esempio n. 5
0
    sys.exit(1)
  from common.conf import Dev as Conf

#open the event logs
LOG_DIR = "/mnt/logs/consensus/"
if not os.path.exists(LOG_DIR):
  os.makedirs(LOG_DIR)
EventLogging.open_logs(os.path.join(LOG_DIR, "consensus_events.out"))

#get the document
conn = httplib.HTTPConnection("%s:%s" % (Conf.AUTH_SERVERS[0]["address"], Conf.AUTH_SERVERS[0]["dirport"]))
conn.request("GET", "/tor/status-vote/current/consensus")
response = conn.getresponse()
responseData = response.read()

#parse all of the bandwidths out of it
bandwidthRe = re.compile('w Bandwidth=(\d{1,10})')

#get bandwidth
bandwidths = [int(r) for r in bandwidthRe.findall(responseData)]
totalBandwidth = sum(bandwidths)
numRelays = len(bandwidths)
bandwidths.sort()
medianBandwidth = bandwidths[numRelays / 2]

#log the median bw, total bw, and number of relays
EventLogging.save_event(Events.NewConsensus(numRelays=numRelays, medianBandwidth=medianBandwidth, totalBandwidth=totalBandwidth))

#all done
EventLogging.close_logs()
Esempio n. 6
0
if not os.path.exists(LOG_DIR):
    os.makedirs(LOG_DIR)
EventLogging.open_logs(os.path.join(LOG_DIR, "consensus_events.out"))

#get the document
conn = httplib.HTTPConnection(
    "%s:%s" %
    (Conf.AUTH_SERVERS[0]["address"], Conf.AUTH_SERVERS[0]["dirport"]))
conn.request("GET", "/tor/status-vote/current/consensus")
response = conn.getresponse()
responseData = response.read()

#parse all of the bandwidths out of it
bandwidthRe = re.compile('w Bandwidth=(\d{1,10})')

#get bandwidth
bandwidths = [int(r) for r in bandwidthRe.findall(responseData)]
totalBandwidth = sum(bandwidths)
numRelays = len(bandwidths)
bandwidths.sort()
medianBandwidth = bandwidths[numRelays / 2]

#log the median bw, total bw, and number of relays
EventLogging.save_event(
    Events.NewConsensus(numRelays=numRelays,
                        medianBandwidth=medianBandwidth,
                        totalBandwidth=totalBandwidth))

#all done
EventLogging.close_logs()
Esempio n. 7
0
def reduce_size(data, amount):
    keys = data.keys()
    count = 0
    for key in keys:
        del data[key]
        count += 1
        if count >= amount:
            return


emails = {}
for i in range(0, 40):
    emails["*****@*****.**" % (random_hex(10))] = random_hex(20)

for email, ref in emails.iteritems():
    EventLogging.save_event(Events.EmailSent(address=email, hexkey=ref))
reduce_size(emails, 5)

for email, ref in emails.iteritems():
    EventLogging.save_event(Events.EmailOpened(hexkey=ref))
    EventLogging.save_event(Events.EmailOpened(hexkey=ref))
reduce_size(emails, 5)

for email, ref in emails.iteritems():
    EventLogging.save_event(Events.EmailLinkVisit(hexkey=ref))
    EventLogging.save_event(Events.EmailLinkVisit(hexkey=ref))
reduce_size(emails, 5)

users = {}
for email, ref in emails.iteritems():
    username = random_hex(8)
Esempio n. 8
0
 def _flush_thread(self, recentEvents):
     """Log an event for each message type and user, essentially"""
     for collectionName, events in recentEvents.iteritems():
         eventType = self._eventTypes.get(collectionName)
         for key, value in events.iteritems():
             EventLogging.save_event(eventType(source=key, amount=value))
Esempio n. 9
0
 def _flush_thread(self, recentEvents):
   """Log an event for each message type and user, essentially"""
   for collectionName, events in recentEvents.iteritems():
     eventType = self._eventTypes.get(collectionName)
     for key, value in events.iteritems():
       EventLogging.save_event(eventType(source=key, amount=value))