Onionbalance API¶
common
¶
argparser
¶
get_common_argparser()
¶
Parses and returns command line arguments.
Source code in repos/onionbalance/onionbalance/common/argparser.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
descriptor
¶
upload_descriptor(controller, signed_descriptor, hsdirs=None, v3_onion_address=None)
¶
Upload descriptor via the Tor control port
If no HSDirs are specified, Tor will upload to what it thinks are the responsible directories
If 'v3_onion_address' is set, this is a v3 HSPOST request, and the address needs to be embedded in the request.
Source code in repos/onionbalance/onionbalance/common/descriptor.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
instance
¶
Instance
¶
Bases: object
Instance represents a back-end load balancing hidden service.
Source code in repos/onionbalance/onionbalance/common/instance.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
|
__eq__(other)
¶
Instance objects are equal if they have the same onion address.
Source code in repos/onionbalance/onionbalance/common/instance.py
90 91 92 93 94 95 96 97 |
|
__hash__()
¶
Define hash method allowing for set comparison between instances.
Source code in repos/onionbalance/onionbalance/common/instance.py
99 100 101 102 103 |
|
__init__(controller, onion_address, authentication_cookie=None)
¶
Initialise an Instance object.
Source code in repos/onionbalance/onionbalance/common/instance.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
|
fetch_descriptor()
¶
Try fetch a fresh descriptor for this service instance from the HSDirs
Source code in repos/onionbalance/onionbalance/common/instance.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|
helper_fetch_all_instance_descriptors(controller, instances, control_password=None)
¶
Try fetch fresh descriptors for all HS instances
Source code in repos/onionbalance/onionbalance/common/instance.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
intro_point_set
¶
IntroductionPointSet
¶
Bases: object
A set of introduction points to included in a HS descriptor.
Provided with a list of available introduction points for each backend instance for an onionbalance service. This object will store the set of available introduction points and allow IPs to be selected from the available set.
This class tracks which introduction points have already been provided and tries to provide the most diverse set of IPs.
Source code in repos/onionbalance/onionbalance/common/intro_point_set.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|
__init__(intro_points)
¶
'intro_points' is a list of lists that looks like this:
[
[
Source code in repos/onionbalance/onionbalance/common/intro_point_set.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
__len__()
¶
Provide the total number of available introduction points
Source code in repos/onionbalance/onionbalance/common/intro_point_set.py
38 39 40 |
|
choose(count=10, shuffle=True)
¶
[Public API]
Retrieve N introduction points from the set of IPs
Where more than count
IPs are available, introduction points are
selected to try and achieve the greatest distribution of introduction
points across all of the available backend instances.
Return a list of IntroductionPoints.
Source code in repos/onionbalance/onionbalance/common/intro_point_set.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|
log
¶
get_config_generator_logger()
¶
Simplified logger for interactive config generator CLI
Source code in repos/onionbalance/onionbalance/common/log.py
32 33 34 35 36 37 38 39 40 41 42 43 |
|
get_logger()
¶
Returns a logger.
Source code in repos/onionbalance/onionbalance/common/log.py
14 15 16 17 18 |
|
setup_file_logger(log_file)
¶
Add log file handler to the existing logger
Source code in repos/onionbalance/onionbalance/common/log.py
21 22 23 24 25 26 27 28 29 |
|
scheduler
¶
Simple scheduler for running jobs at regular intervals
Job
¶
Bases: object
Object to represent a scheduled job task
Source code in repos/onionbalance/onionbalance/common/scheduler.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
should_run
property
¶
Check if the job should be run now
__lt__(other)
¶
Jobs are sorted based on their next scheduled run time
Source code in repos/onionbalance/onionbalance/common/scheduler.py
28 29 30 31 32 |
|
__repr__()
¶
Return human readable representation of the Job and arguments
Source code in repos/onionbalance/onionbalance/common/scheduler.py
54 55 56 57 58 59 60 61 62 |
|
run(override_run_time=None)
¶
Run job then reschedule it in the job list
Source code in repos/onionbalance/onionbalance/common/scheduler.py
41 42 43 44 45 46 47 48 49 50 51 52 |
|
add_job(interval, function, *job_args, **job_kwargs)
¶
Add a job to be executed at regular intervals
The interval
value is in seconds, starting from now.
Source code in repos/onionbalance/onionbalance/common/scheduler.py
65 66 67 68 69 70 71 72 |
|
run_all(delay_seconds=0)
¶
Run all jobs at delay_seconds
regardless of their schedule
Source code in repos/onionbalance/onionbalance/common/scheduler.py
82 83 84 85 86 87 88 |
|
run_forever(check_interval=1)
¶
Run jobs forever
Source code in repos/onionbalance/onionbalance/common/scheduler.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
signalhandler
¶
SignalHandler
¶
Bases: object
Handle signals sent to the Onionbalance daemon process
Source code in repos/onionbalance/onionbalance/common/signalhandler.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
__init__(version, controller, status_socket=None)
¶
Setup signal handler
Source code in repos/onionbalance/onionbalance/common/signalhandler.py
16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
status
¶
Base class to provide status over Unix socket Default path: /var/run/onionbalance/control
BaseStatusSocket
¶
Bases: object
For creating a Unix domain socket which emits a summary of the Onionbalance status when a client connects.
Source code in repos/onionbalance/onionbalance/common/status.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
|
cleanup_socket_file()
¶
Try to remove the socket file if it exists already
Source code in repos/onionbalance/onionbalance/common/status.py
23 24 25 26 27 28 29 30 31 32 |
|
close()
¶
Close the unix domain socket and remove its file
Source code in repos/onionbalance/onionbalance/common/status.py
34 35 36 37 38 39 40 41 42 43 44 45 |
|
util
¶
reauthenticate(controller, logger, control_password=None)
¶
Tries to authenticate to the controller
Source code in repos/onionbalance/onionbalance/common/util.py
64 65 66 67 68 69 70 71 72 |
|
config_generator
¶
config_generator
¶
ConfigGenerator
¶
Bases: object
Source code in repos/onionbalance/onionbalance/config_generator/config_generator.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
|
get_num_instances(i)
¶
Get the number of instances and a tag name for them.
Source code in repos/onionbalance/onionbalance/config_generator/config_generator.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
|
get_num_services()
¶
Get the number of services this OnionBalance should support
Source code in repos/onionbalance/onionbalance/config_generator/config_generator.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
|
get_output_path()
¶
Get path to output directory and create if needed
Source code in repos/onionbalance/onionbalance/config_generator/config_generator.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|
get_torrc_port_line()
¶
Get the HiddenServicePort line for the instance torrc file
Source code in repos/onionbalance/onionbalance/config_generator/config_generator.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
|
load_master_key(i)
¶
Return the key and onion address of the frontend service.
Source code in repos/onionbalance/onionbalance/config_generator/config_generator.py
122 123 124 125 126 127 128 129 130 |
|
try_make_dir(path)
¶
Try to create a directory (including any parent directories)
Source code in repos/onionbalance/onionbalance/config_generator/config_generator.py
53 54 55 56 57 58 59 60 61 |
|
main()
¶
Entry point for interactive config file generation.
Source code in repos/onionbalance/onionbalance/config_generator/config_generator.py
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
|
parse_cmd_args()
¶
Parses and returns command line arguments for config generator
Source code in repos/onionbalance/onionbalance/config_generator/config_generator.py
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
|
hs_v3
¶
consensus
¶
Consensus
¶
Bases: object
This represents a consensus object.
It's initialized once in startup and refreshed during the runtime using the refresh() method to get the latest consensus.
Source code in repos/onionbalance/onionbalance/hs_v3/consensus.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
|
get_blinding_param(identity_pubkey, time_period_number)
¶
Calculate the HSv3 blinding parameter as specified in rend-spec-v3.txt section A.2:
h = H(BLIND_STRING | A | s | B | N) BLIND_STRING = "Derive temporary signing key" | INT_1(0) N = "key-blind" | INT_8(period-number) | INT_8(period_length) B = "(1511[...]2202, 4631[...]5960)"
Use the time period number in 'time_period_number'.
Source code in repos/onionbalance/onionbalance/hs_v3/consensus.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
|
get_routerstatuses()
¶
Give access to the routerstatus entries in this consensus
Source code in repos/onionbalance/onionbalance/hs_v3/consensus.py
58 59 60 61 62 63 64 65 |
|
get_start_time_of_current_srv_run()
¶
Return the start time of the current SR protocol run using the times from the current consensus. For example, if the latest consensus valid-after is 23/06/2017 23:00:00 and a full SR protocol run is 24 hours, this function returns 23/06/2017 00:00:00.
TODO: unittest
Source code in repos/onionbalance/onionbalance/hs_v3/consensus.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
|
get_start_time_of_next_time_period(valid_after=None)
¶
Return the start time of the upcoming time period
Source code in repos/onionbalance/onionbalance/hs_v3/consensus.py
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
|
get_time_period_length()
¶
Get the HSv3 time period length in minutes
Source code in repos/onionbalance/onionbalance/hs_v3/consensus.py
164 165 166 167 168 169 170 171 172 173 174 175 |
|
get_time_period_num(valid_after=None)
¶
Get time period number for this 'valid_after'.
valid_after is a datetime (if not set, we get it ourselves) time_period_length set to default value of 1440 minutes == 1 day
Source code in repos/onionbalance/onionbalance/hs_v3/consensus.py
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
|
is_live()
¶
Return True if the consensus is live.
This function replicates the behavior of the little-t-tor networkstatus_get_reasonably_live_consensus() function.
Source code in repos/onionbalance/onionbalance/hs_v3/consensus.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
|
refresh()
¶
Attempt to refresh the consensus with the latest one available.
Source code in repos/onionbalance/onionbalance/hs_v3/consensus.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
|
descriptor
¶
IntroductionPointSetV3
¶
Bases: IntroductionPointSet
This class represents a set of introduction points (which are actually stem.descriptor.hidden_service.IntroductionPointV3 objects)
It gives us a nice way to compare sets of introduction poinst between them, to see if they are different.
It also preserves all the functionality of onionbalance.common.intro_point_set.IntroductionPointSet which allows you to sample introduction points out of the set.
Source code in repos/onionbalance/onionbalance/hs_v3/descriptor.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
|
__eq__(other)
¶
Compares two IntroductionPointSetV3 objects and returns True if they have the same introduction points in them.
Source code in repos/onionbalance/onionbalance/hs_v3/descriptor.py
55 56 57 58 59 60 61 62 63 64 65 66 |
|
__init__(introduction_points)
¶
'introduction_points' is a list of lists where each internal list contains the introduction points of an instance
Source code in repos/onionbalance/onionbalance/hs_v3/descriptor.py
36 37 38 39 40 41 42 43 44 45 46 47 |
|
get_intro_points_flat()
¶
Flatten the .intro_points list of list into a single list and return it
Source code in repos/onionbalance/onionbalance/hs_v3/descriptor.py
49 50 51 52 53 |
|
OBDescriptor
¶
Bases: V3Descriptor
A v3 descriptor created by Onionbalance and meant to be published to the network.
This class supports generating descriptors.
Can raise BadDescriptor if we can't or should not generate a valid descriptor.
Source code in repos/onionbalance/onionbalance/hs_v3/descriptor.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
|
ReceivedDescriptor
¶
Bases: V3Descriptor
An instance v3 descriptor received from the network.
This class supports parsing descriptors.
Source code in repos/onionbalance/onionbalance/hs_v3/descriptor.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
|
__init__(desc_text, onion_address)
¶
Parse a descriptor in 'desc_text' and return an ReceivedDescriptor object.
Raises BadDescriptor if the descriptor cannot be used.
Source code in repos/onionbalance/onionbalance/hs_v3/descriptor.py
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
|
is_old()
¶
Return True if this received descriptor is old and we should consider the instance as offline.
Source code in repos/onionbalance/onionbalance/hs_v3/descriptor.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
|
V3Descriptor
¶
Bases: object
A generic v3 descriptor.
Serves as the base class for OBDescriptor and ReceivedDescriptor which implement more specific functionalities.
Source code in repos/onionbalance/onionbalance/hs_v3/descriptor.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
get_blinded_key()
¶
Extract and return the blinded key from the descriptor
Source code in repos/onionbalance/onionbalance/hs_v3/descriptor.py
91 92 93 94 95 96 97 98 |
|
get_intro_points()
¶
Get the raw intro points for this descriptor.
Source code in repos/onionbalance/onionbalance/hs_v3/descriptor.py
85 86 87 88 89 |
|
get_size()
¶
Return size of v3 descriptor in bytes
Source code in repos/onionbalance/onionbalance/hs_v3/descriptor.py
100 101 102 103 104 |
|
ext
¶
ed25519_exts_ref
¶
Reference implementations for the ed25519 tweaks that Tor uses.
Includes self-tester and test vector generator.
hashring
¶
get_responsible_hsdirs(blinded_pubkey, is_first_descriptor)
¶
Return a list with the responsible HSDirs for a service with 'blinded_pubkey'.
The returned list is a list of fingerprints.
Source code in repos/onionbalance/onionbalance/hs_v3/hashring.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
|
get_srv_and_time_period(is_first_descriptor)
¶
Return SRV and time period based on current consensus time
Source code in repos/onionbalance/onionbalance/hs_v3/hashring.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
|
instance
¶
InstanceV3
¶
Bases: Instance
This is a V3 onionbalance instance
Source code in repos/onionbalance/onionbalance/hs_v3/instance.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
|
get_intros_for_publish()
¶
Get a list of stem.descriptor.IntroductionPointV3 objects for this descriptor
Raise :InstanceHasNoDescriptor: if there is no descriptor for this instance Raise :InstanceIsOffline: if the instance is offline.
Source code in repos/onionbalance/onionbalance/hs_v3/instance.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
|
has_onion_address(onion_address)
¶
Return True if this instance has this onion address
Source code in repos/onionbalance/onionbalance/hs_v3/instance.py
32 33 34 35 36 37 38 39 40 41 42 |
|
register_descriptor(descriptor_text, onion_address)
¶
We received a descriptor (with 'descriptor_text') for 'onion_address'. Register it to this instance.
Source code in repos/onionbalance/onionbalance/hs_v3/instance.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
|
manager
¶
main(args)
¶
This is the entry point of v3 functionality.
Initialize onionbalance, schedule future jobs and let the scheduler do its thing.
Source code in repos/onionbalance/onionbalance/hs_v3/manager.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
|
onionbalance
¶
Onionbalance
¶
Bases: object
Onionbalance singleton that represents this onionbalance runtime.
Contains various objects that are useful to other onionbalance modules so this is imported from all over the codebase.
Source code in repos/onionbalance/onionbalance/hs_v3/onionbalance.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
|
handle_new_desc_content_event(desc_content_event)
¶
Parse HS_DESC_CONTENT response events for descriptor content
Update the HS instance object with the data from the new descriptor.
Source code in repos/onionbalance/onionbalance/hs_v3/onionbalance.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
|
handle_new_desc_event(desc_event)
¶
Parse HS_DESC response events
Source code in repos/onionbalance/onionbalance/hs_v3/onionbalance.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|
handle_new_status_event(status_event)
¶
Parse Tor status events such as "STATUS_GENERAL"
Source code in repos/onionbalance/onionbalance/hs_v3/onionbalance.py
173 174 175 176 177 178 179 180 181 182 183 |
|
init_subsystems(args)
¶
Initialize subsystems (this is resource intensive)
Source code in repos/onionbalance/onionbalance/hs_v3/onionbalance.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
publish_all_descriptors()
¶
For each service attempt to publish all descriptors
Source code in repos/onionbalance/onionbalance/hs_v3/onionbalance.py
149 150 151 152 153 154 155 156 157 158 159 160 |
|
reload_config()
¶
Reload configuration and reset job scheduler
Source code in repos/onionbalance/onionbalance/hs_v3/onionbalance.py
226 227 228 229 230 231 232 233 234 235 236 |
|
service
¶
OnionbalanceService
¶
Bases: object
Service represents a front-facing hidden service which should be load-balanced.
Source code in repos/onionbalance/onionbalance/hs_v3/service.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 |
|
__init__(service_config_data, config_path)
¶
With 'config_data' straight out of the config file, create the service and its instances. 'config_path' is the full path to the config file.
Raise ValueError if the config file is not well formatted
Source code in repos/onionbalance/onionbalance/hs_v3/service.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
|
get_all_intros_for_publish()
¶
Return an IntroductionPointSetV3 with all the intros of all the instances of this service.
Source code in repos/onionbalance/onionbalance/hs_v3/service.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
|
has_onion_address(onion_address)
¶
Return True if this service has this onion address
Source code in repos/onionbalance/onionbalance/hs_v3/service.py
62 63 64 65 66 67 68 69 70 71 72 |
|
status
¶
Provide status over Unix socket Default path: /var/run/onionbalance/control
StatusSocket
¶
Bases: BaseStatusSocket
Create a Unix domain socket which emits a summary of the Onionbalance status when a client connects.
Source code in repos/onionbalance/onionbalance/hs_v3/status.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
|
__init__(status_socket_location, balance)
¶
Create the Unix domain socket status server and start in a thread
Example:: socat - unix-connect:/var/run/onionbalance/control
{"services": [{"instances": [{"introModified": "2020-06-16 19:35:17", "ipsNum": 3, "onionAddress": "vkmiy6biqcyphtx5exswxl5sjus2vn2b6pzir7lz5akudhwbqk5muead.onion"}], "onionAddress": "bvy46sg2b5dokczabwv2pabqlrps3lppweyrebhat6gjieo2avojdvad.onion.onion", "timestamp": "2020-06-16 19:36:01"}]}
Source code in repos/onionbalance/onionbalance/hs_v3/status.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
|
StatusSocketHandlerImpl
¶
Bases: BaseRequestHandler
, StatusSocketHandlerMixin
Handler for new domain socket connections
Source code in repos/onionbalance/onionbalance/hs_v3/status.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
handle()
¶
Prepare and output the status summary when a connection is received
Source code in repos/onionbalance/onionbalance/hs_v3/status.py
65 66 67 68 69 |
|
ThreadingSocketServer
¶
Bases: ThreadingMixIn
, UnixStreamServer
Unix socket server with threading
Source code in repos/onionbalance/onionbalance/hs_v3/status.py
82 83 84 85 86 |
|
stem_controller
¶
StemController
¶
Bases: object
This class is our interface to the control port
Source code in repos/onionbalance/onionbalance/hs_v3/stem_controller.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
|
mark_tor_as_active()
¶
Send the ACTIVE signal to the control port so that Tor does not become dormant.
Source code in repos/onionbalance/onionbalance/hs_v3/stem_controller.py
53 54 55 56 57 58 59 60 61 |
|
handle_new_desc_content_event_wrapper(desc_content_event)
¶
A wrapper for this control port event (see above)
Source code in repos/onionbalance/onionbalance/hs_v3/stem_controller.py
35 36 37 38 39 40 41 |
|
handle_new_desc_event_wrapper(desc_event)
¶
A wrapper for this control port event (see above)
Source code in repos/onionbalance/onionbalance/hs_v3/stem_controller.py
26 27 28 29 30 31 32 |
|
handle_new_status_event_wrapper(status_event)
¶
A wrapper for this control port event. We need this so that we print tracebacks on the listener thread (also see https://stem.torproject.org/tutorials/tortoise_and_the_hare.html#advanced-listeners)
Source code in repos/onionbalance/onionbalance/hs_v3/stem_controller.py
13 14 15 16 17 18 19 20 21 22 23 |
|
tor_ed25519
¶
TorEd25519PrivateKey
¶
Bases: object
Represents the private part of a blinded ed25519 key of an onion service and should expose a public_key() method and a sign() method.
Source code in repos/onionbalance/onionbalance/hs_v3/tor_ed25519.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
__class__
property
¶
This is an epic hack to make this class look like a hazmat ed25519 public key in the eyes of stem: https://github.com/asn-d6/onionbalance/issues/10#issuecomment-610425916
The class_ attribute is what's being used by unittest.mock and the C API to trick isinstance() checks, so as long as stem uses isinstance() this is gonna work: https://docs.python.org/3/library/unittest.mock.html#unittest.mock.Mock.__class https://docs.python.org/3/c-api/object.html#c.PyObject_IsInstance
TorEd25519PublicKey
¶
Bases: object
Represents the public blinded ed25519 key of an onion service and should expose a public_bytes() method and a verify() method.
Source code in repos/onionbalance/onionbalance/hs_v3/tor_ed25519.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
|
verify(signature, message)
¶
raises exception if sig not valid
Source code in repos/onionbalance/onionbalance/hs_v3/tor_ed25519.py
120 121 122 123 124 |
|
load_tor_key_from_disk(key_bytes)
¶
Load a private identity key from little-t-tor.
Source code in repos/onionbalance/onionbalance/hs_v3/tor_ed25519.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
tor_node
¶
Node
¶
Bases: object
Represents a Tor node.
A Node instance gets created for each node of a consensus. When we fetch a new consensus, we create new Node instances for the routers found inside.
The 'microdescriptor' and 'routerstatus' fields of this object are immutable: They are set once when we receive the consensus based on the state of the network at that point, and they stay like that until we get a new consensus.
Source code in repos/onionbalance/onionbalance/hs_v3/tor_node.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
get_hsdir_index(srv, period_num)
¶
Get the HSDir index for this node:
hsdir_index(node) = H("node-idx" | node_identity | shared_random_value | INT_8(period_num) | INT_8(period_length) )
Raises NoHSDir or NoEd25519Identity in case of errors.
Source code in repos/onionbalance/onionbalance/hs_v3/tor_node.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
manager
¶
Global entry point