| 122 | # blobHandler to reassemble the packets in the traffic |
| 123 | # Bitcoin traffic uses TCP |
| 124 | def blob_handler(self, conn, blob): |
| 125 | try: |
| 126 | data = blob.data |
| 127 | data_str = ''.join(chr(x) for x in data) |
| 128 | data_len = len(data) |
| 129 | except: |
| 130 | self.logger.error('could not parse session data') |
| 131 | return |
| 132 | |
| 133 | # Only continue if the packet contains data |
| 134 | if not data: |
| 135 | return |
| 136 | |
| 137 | |
| 138 | # Default mining.notify fields to None |
| 139 | job_id = None |
| 140 | prev_blk_hash = None |
| 141 | gen_tx1 = None |
| 142 | gen_tx2 = None |
| 143 | merkle_branches = None |
| 144 | blk_ver = None |
| 145 | difficulty = None |
| 146 | curr_time = None |
| 147 | clean_jobs = None |
| 148 | |
| 149 | # If the payload contains JSON |
| 150 | if data_str.startswith('{"'): |
| 151 | self.JSON = True |
| 152 | try: |
| 153 | # split JSON objects by newline |
| 154 | for rawjs in data_str.split("\n"): |
| 155 | if rawjs: |
| 156 | js = json.loads(rawjs) |
| 157 | try: |
| 158 | if "method" in js and js["method"]: |
| 159 | # Create a dictionary of sets of mining methods |
| 160 | # indexed by their associated conn.addr (sip, dip, sport, dport) |
| 161 | self.methods.setdefault(conn.addr, set([])).add(js["method"]) |
| 162 | |
| 163 | if js["method"] == "mining.subscribe": |
| 164 | self.miners[conn.addr] = js["params"][0] |
| 165 | |
| 166 | if js["method"] == "mining.authorize": |
| 167 | if "params" in js and js['params'][0]: |
| 168 | # Grab the Bitcoin User ID (sometimes a wallet id) |
| 169 | # which is being authorized |
| 170 | self.auth_ids[conn.addr] = js["params"][0] |
| 171 | |
| 172 | if js['params'][1]: |
| 173 | self.auth_ids[conn.addr] = "".join(( |
| 174 | self.auth_ids[conn.addr], " / ", str(js['params'][1]) )) |
| 175 | |
| 176 | if js["method"] == "mining.notify": |
| 177 | self.NOTIFY = True |
| 178 | if "params" in js and js['params']: |
| 179 | job_id, prev_blk_hash, gen_tx1, gen_tx2, merkle_branches, blk_ver, difficulty, curr_time, clean_jobs = js['params'] |
| 180 | self.job_ids.setdefault(conn.addr, []).append(job_id) |
| 181 | self.notify_params[conn.addr] = [self.job_ids, prev_blk_hash, gen_tx1, |