Format Python code with (black)
This commit is contained in:
@@ -638,6 +638,18 @@ def zts_init_set_port(port):
|
||||
return _libzt.zts_init_set_port(port)
|
||||
|
||||
|
||||
def zts_init_set_random_port_range(start_port, end_port):
|
||||
return _libzt.zts_init_set_random_port_range(start_port, end_port)
|
||||
|
||||
|
||||
def zts_init_allow_secondary_port(allowed):
|
||||
return _libzt.zts_init_allow_secondary_port(allowed)
|
||||
|
||||
|
||||
def zts_init_allow_port_mapping(allowed):
|
||||
return _libzt.zts_init_allow_port_mapping(allowed)
|
||||
|
||||
|
||||
def zts_init_allow_net_cache(allowed):
|
||||
return _libzt.zts_init_allow_net_cache(allowed)
|
||||
|
||||
@@ -1137,6 +1149,10 @@ def zts_bsd_shutdown(fd, how):
|
||||
return _libzt.zts_bsd_shutdown(fd, how)
|
||||
|
||||
|
||||
def zts_socket(family, type, protocol):
|
||||
return _libzt.zts_socket(family, type, protocol)
|
||||
|
||||
|
||||
def zts_connect(fd, ipstr, port, timeout_ms):
|
||||
return _libzt.zts_connect(fd, ipstr, port, timeout_ms)
|
||||
|
||||
@@ -1145,10 +1161,46 @@ def zts_bind(fd, ipstr, port):
|
||||
return _libzt.zts_bind(fd, ipstr, port)
|
||||
|
||||
|
||||
def zts_listen(fd, backlog):
|
||||
return _libzt.zts_listen(fd, backlog)
|
||||
|
||||
|
||||
def zts_accept(fd, remote_addr, len, port):
|
||||
return _libzt.zts_accept(fd, remote_addr, len, port)
|
||||
|
||||
|
||||
def zts_send(fd, buf, len, flags):
|
||||
return _libzt.zts_send(fd, buf, len, flags)
|
||||
|
||||
|
||||
def zts_recv(fd, buf, len, flags):
|
||||
return _libzt.zts_recv(fd, buf, len, flags)
|
||||
|
||||
|
||||
def zts_read(fd, buf, len):
|
||||
return _libzt.zts_read(fd, buf, len)
|
||||
|
||||
|
||||
def zts_write(fd, buf, len):
|
||||
return _libzt.zts_write(fd, buf, len)
|
||||
|
||||
|
||||
def zts_shutdown_rd(fd):
|
||||
return _libzt.zts_shutdown_rd(fd)
|
||||
|
||||
|
||||
def zts_shutdown_wr(fd):
|
||||
return _libzt.zts_shutdown_wr(fd)
|
||||
|
||||
|
||||
def zts_shutdown_rdwr(fd):
|
||||
return _libzt.zts_shutdown_rdwr(fd)
|
||||
|
||||
|
||||
def zts_close(fd):
|
||||
return _libzt.zts_close(fd)
|
||||
|
||||
|
||||
def zts_getpeername(fd, remote_addr_str, len, port):
|
||||
return _libzt.zts_getpeername(fd, remote_addr_str, len, port)
|
||||
|
||||
@@ -1179,6 +1231,14 @@ def zts_set_no_delay(fd, enabled):
|
||||
return _libzt.zts_set_no_delay(fd, enabled)
|
||||
|
||||
|
||||
def zts_get_last_socket_error(fd):
|
||||
return _libzt.zts_get_last_socket_error(fd)
|
||||
|
||||
|
||||
def zts_get_data_available(fd):
|
||||
return _libzt.zts_get_data_available(fd)
|
||||
|
||||
|
||||
def zts_get_no_delay(fd):
|
||||
return _libzt.zts_get_no_delay(fd)
|
||||
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
'''Example low-level socket usage'''
|
||||
"""Example low-level socket usage"""
|
||||
|
||||
import time
|
||||
import sys
|
||||
|
||||
import libzt
|
||||
|
||||
|
||||
def print_usage():
|
||||
'''print help'''
|
||||
"""print help"""
|
||||
print(
|
||||
"\nUsage: <server|client> <storage_path> <net_id> <remote_ip> <remote_port>\n"
|
||||
)
|
||||
@@ -18,6 +19,7 @@ def print_usage():
|
||||
print("Too many arguments")
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
#
|
||||
# (Optional) Event handler
|
||||
#
|
||||
@@ -35,6 +37,7 @@ def on_zerotier_event(event_code, id):
|
||||
if event_code == libzt.ZTS_EVENT_PEER_RELAY:
|
||||
print("ZTS_EVENT_PEER_RELAY (" + str(event_code) + ") : " + hex(id))
|
||||
|
||||
|
||||
#
|
||||
# Main
|
||||
#
|
||||
@@ -121,7 +124,7 @@ def main():
|
||||
client.connect((remote_ip, remote_port))
|
||||
data = "Hello, world!"
|
||||
print("send: ", data)
|
||||
sent_bytes = client.send(data.encode('utf-8'))
|
||||
sent_bytes = client.send(data.encode("utf-8"))
|
||||
print("sent: " + str(sent_bytes) + " byte(s)")
|
||||
data = client.recv(1024)
|
||||
print("recv: ", repr(data))
|
||||
@@ -129,5 +132,6 @@ def main():
|
||||
print(ex)
|
||||
print("errno=", libzt.errno())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user