remove useless callbacks
parent
48b9178fe1
commit
aa58132220
|
@ -64,8 +64,7 @@ async def new_destination(sam_address=i2plib.sam.DEFAULT_ADDRESS, loop=None,
|
|||
async def create_session(session_name, sam_address=i2plib.sam.DEFAULT_ADDRESS,
|
||||
loop=None, style="STREAM",
|
||||
signature_type=i2plib.sam.Destination.default_sig_type,
|
||||
destination=None, options={}, session_created=None,
|
||||
args=()):
|
||||
destination=None, options={}):
|
||||
"""A coroutine used to create a new SAM session.
|
||||
|
||||
:param session_name: Session nick name
|
||||
|
@ -79,10 +78,6 @@ async def create_session(session_name, sam_address=i2plib.sam.DEFAULT_ADDRESS,
|
|||
instance or None. TRANSIENT destination is used when it
|
||||
is None.
|
||||
:param options: (optional) A dict object with i2cp options
|
||||
:param session_created: (optional) A coroutine to be executed after the
|
||||
session is created. Executed with arguments
|
||||
(loop, reader, writer, destination, \*args)
|
||||
:param args: (optional) Arguments for a session_created coroutine
|
||||
:return: A (reader, writer) pair
|
||||
"""
|
||||
logging.debug("Creating session {}".format(session_name))
|
||||
|
@ -110,26 +105,18 @@ async def create_session(session_name, sam_address=i2plib.sam.DEFAULT_ADDRESS,
|
|||
reply["DESTINATION"], has_private_key=True)
|
||||
logging.debug(destination.base32)
|
||||
logging.debug("Session created {}".format(session_name))
|
||||
if session_created:
|
||||
asyncio.ensure_future(session_created(loop, reader, writer,
|
||||
destination, *args), loop=loop)
|
||||
return (reader, writer)
|
||||
else:
|
||||
raise i2plib.exceptions.SAM_EXCEPTIONS[reply["RESULT"]]()
|
||||
|
||||
async def stream_connect(session_name, destination,
|
||||
sam_address=i2plib.sam.DEFAULT_ADDRESS, loop=None,
|
||||
stream_connected=None, args=()):
|
||||
sam_address=i2plib.sam.DEFAULT_ADDRESS, loop=None):
|
||||
"""A coroutine used to connect to a remote I2P destination.
|
||||
|
||||
:param session_name: Session nick name
|
||||
:param destination: I2P destination to connect to
|
||||
:param sam_address: (optional) SAM API address
|
||||
:param loop: (optional) Event loop instance
|
||||
:param stream_connected: (optional) A coroutine to be executed after the
|
||||
connection has been established. Executed with arguments
|
||||
(loop, session_name, reader, writer, \*args)
|
||||
:param args: (optional) Arguments for a stream_connected coroutine
|
||||
:return: A (reader, writer) pair
|
||||
"""
|
||||
logging.debug("Connecting stream {}".format(session_name))
|
||||
|
@ -144,36 +131,23 @@ async def stream_connect(session_name, destination,
|
|||
reply = parse_reply(await reader.read(BUFFER_SIZE))
|
||||
if reply.ok:
|
||||
logging.debug("Stream connected {}".format(session_name))
|
||||
if stream_connected:
|
||||
asyncio.ensure_future(
|
||||
stream_connected(loop, session_name, reader, writer, *args),
|
||||
loop=loop)
|
||||
return (reader, writer)
|
||||
else:
|
||||
raise i2plib.exceptions.SAM_EXCEPTIONS[reply["RESULT"]]()
|
||||
|
||||
async def stream_accept(session_name, sam_address=i2plib.sam.DEFAULT_ADDRESS,
|
||||
loop=None, stream_connected=None,
|
||||
args=()):
|
||||
loop=None):
|
||||
"""A coroutine used to accept a connection from the I2P network.
|
||||
|
||||
:param session_name: Session nick name
|
||||
:param sam_address: (optional) SAM API address
|
||||
:param loop: (optional) Event loop instance
|
||||
:param stream_connected: (optional) A coroutine to be executed after the
|
||||
connection has been established. Executed with arguments
|
||||
(loop, session_name, reader, writer, \*args)
|
||||
:param args: (optional) Arguments for a stream_connected coroutine
|
||||
:return: A (reader, writer) pair
|
||||
"""
|
||||
reader, writer = await get_sam_socket(sam_address, loop)
|
||||
writer.write(i2plib.sam.stream_accept(session_name, silent="false"))
|
||||
reply = parse_reply(await reader.read(BUFFER_SIZE))
|
||||
if reply.ok:
|
||||
if stream_connected:
|
||||
asyncio.ensure_future(
|
||||
stream_connected(loop, session_name, reader, writer, *args),
|
||||
loop=loop)
|
||||
return (reader, writer)
|
||||
else:
|
||||
raise i2plib.exceptions.SAM_EXCEPTIONS[reply["RESULT"]]()
|
||||
|
|
Loading…
Reference in New Issue