This repository was archived by the owner on Jul 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Python API: move the really_get_paths function into the API
#41
Open
AnotherKamila
wants to merge
3
commits into
master
Choose a base branch
from
python-api-change
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,23 @@ | ||
| """Rudimentary Python API for SCION: wraps a simplified Go API. | ||
|
|
||
| To use this, you need to build scion_api.go, which will give you a .so that | ||
| this file provides bindings for. Place both the .so and this file into the same | ||
| directory, somewhere in your Python path (e.g. into .). | ||
|
|
||
| The API consists of: | ||
| - set_log_level(level) | ||
| - init() | ||
| - addr = local_address() | ||
| - paths = get_paths(destination) | ||
| - fd = connect(destination, path) | ||
| - fd.close() | ||
| - fd.write(buffer) | ||
| - fd = listen(port) | ||
| - addr, n = fd.read(buffer) | ||
| """ | ||
|
|
||
| __all__ = ['SCIONException', 'HostInfo', 'FwdPathMeta', 'Interface', 'Path', 'connect', | ||
| 'set_log_level', 'init', 'local_address', 'paths', 'listen'] | ||
| 'set_log_level', 'init', 'local_address', 'get_paths', 'listen'] | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, forgot about that, thanks! |
||
|
|
||
| from ctypes import * | ||
| from collections import namedtuple | ||
|
|
@@ -164,7 +182,7 @@ def local_address(): | |
| _lib.Paths.restype = c_char_p | ||
| _lib.FreePathsMemory.argtypes = [POINTER(_PathReplyEntry), c_size_t] | ||
| _lib.FreePathsMemory.restype = c_char_p | ||
| def paths(destination): | ||
| def _call_paths(destination): | ||
| paths_n = c_size_t() | ||
| paths = (POINTER(_PathReplyEntry))() | ||
| err = _lib.Paths(byref(paths_n), byref(paths), _str_to_cstr(destination)) | ||
|
|
@@ -229,3 +247,32 @@ def listen(port): | |
| conn = connect(None, None) | ||
| conn.fd = int(fd.value) | ||
| return conn | ||
|
|
||
|
|
||
| def get_paths(destination, loop_till_have_paths=True): | ||
| """Returns a list of SCION Paths. | ||
|
|
||
| Warning: This function will change! However, using it with only the | ||
| destination (and leaving all other arguments default) will have the same | ||
| semantics, i.e. will block until it can return a non-empty list of paths to | ||
| the destination. | ||
|
|
||
| Getting paths in SCION can be async/non-blocking: if you pass | ||
| loop_till_have_paths=False, this function will return immediately with | ||
| whatever paths are in the cache right now. If this is the first time you're | ||
| looking up this destination, the cache may be empty (and this will return | ||
| []). | ||
|
|
||
| If loop_till_have_paths=True, this function will retry until it gets | ||
| at least one path. (Note that if the destination is unreachable, this will | ||
| loop forever!) | ||
|
|
||
| Ideally, this function would be able to distinguish between "no paths in | ||
| cache" and "unreachable". That is a TODO. | ||
| """ | ||
| while True: | ||
| try: | ||
| return _call_paths(destination) | ||
| except SCIONException as e: | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why did we delete the sleep here? |
||
| if not loop_till_have_paths: | ||
| raise e | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did we pass False here?