-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add API method to generate an I2P Destination
- Loading branch information
Showing
6 changed files
with
140 additions
and
32 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from twisted.internet.endpoints import clientFromString | ||
|
||
from txi2p.helpers import getApi | ||
from txi2p.sam import api as samApi | ||
|
||
|
||
_apiGenerators = { | ||
'SAM': samApi.generateDestination, | ||
} | ||
|
||
def generateDestination(reactor, keyfile, api=None, apiEndpoint=None): | ||
api, apiEndpoint = getApi(api, apiEndpoint, _apiGenerators) | ||
if isinstance(apiEndpoint, str): | ||
apiEndpoint = clientFromString(reactor, apiEndpoint) | ||
return _apiGenerators[api](keyfile, apiEndpoint) |
This file contains 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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
DEFAULT_ENDPOINT = { | ||
'BOB': 'tcp:127.0.0.1:2827', | ||
'SAM': 'tcp:127.0.0.1:7656', | ||
} | ||
|
||
DEFAULT_API = 'BOB' | ||
|
||
|
||
def getApi(api, apiEndpoint, apiDict): | ||
if not api: | ||
if apiEndpoint: | ||
raise ValueError('api must be specified if apiEndpoint is given') | ||
else: | ||
api = DEFAULT_API | ||
|
||
if api not in apiDict: | ||
raise ValueError('Specified I2P API is invalid or unsupported') | ||
|
||
if not apiEndpoint: | ||
apiEndpoint = DEFAULT_ENDPOINT[api] | ||
|
||
return (api, apiEndpoint) |
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from txi2p.sam.session import DestGenerateFactory | ||
|
||
|
||
def generateDestination(keyfile, samEndpoint): | ||
destFac = DestGenerateFactory(keyfile) | ||
d = samEndpoint.connect(destFac) | ||
d.addCallback(lambda proto: destFac.deferred) | ||
return d |
This file contains 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 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