2020-04-22 10:07:13 +00:00
|
|
|
##########################################################
|
|
|
|
# This RNS example demonstrates a minimal setup, that #
|
|
|
|
# will start up the Reticulum Network Stack, generate a #
|
|
|
|
# new destination, and let the user send an announce. #
|
|
|
|
##########################################################
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import RNS
|
|
|
|
|
|
|
|
# Let's define an app name. We'll use this for all
|
|
|
|
# destinations we create. Since this basic example
|
|
|
|
# is part of a range of example utilities, we'll put
|
|
|
|
# them all within the app namespace "example_utilities"
|
2021-05-15 08:57:54 +00:00
|
|
|
APP_NAME = "example_utilities"
|
2020-04-22 10:07:13 +00:00
|
|
|
|
|
|
|
# This initialisation is executed when the program is started
|
|
|
|
def program_setup(configpath):
|
2020-08-13 10:15:56 +00:00
|
|
|
# We must first initialise Reticulum
|
|
|
|
reticulum = RNS.Reticulum(configpath)
|
2024-10-07 08:52:43 +00:00
|
|
|
|
2020-08-13 10:15:56 +00:00
|
|
|
# Randomly create a new identity for our example
|
|
|
|
identity = RNS.Identity()
|
2020-04-22 10:07:13 +00:00
|
|
|
|
2020-08-13 10:15:56 +00:00
|
|
|
# Using the identity we just created, we create a destination.
|
|
|
|
# Destinations are endpoints in Reticulum, that can be addressed
|
|
|
|
# and communicated with. Destinations can also announce their
|
|
|
|
# existence, which will let the network know they are reachable
|
2023-10-01 09:46:30 +00:00
|
|
|
# and automatically create paths to them, from anywhere else
|
2020-08-13 10:15:56 +00:00
|
|
|
# in the network.
|
2021-05-17 17:10:11 +00:00
|
|
|
destination = RNS.Destination(
|
|
|
|
identity,
|
|
|
|
RNS.Destination.IN,
|
|
|
|
RNS.Destination.SINGLE,
|
|
|
|
APP_NAME,
|
|
|
|
"minimalsample"
|
|
|
|
)
|
2020-04-22 10:07:13 +00:00
|
|
|
|
2020-08-13 10:15:56 +00:00
|
|
|
# We configure the destination to automatically prove all
|
2023-10-01 09:46:30 +00:00
|
|
|
# packets addressed to it. By doing this, RNS will automatically
|
2020-08-13 10:15:56 +00:00
|
|
|
# generate a proof for each incoming packet and transmit it
|
|
|
|
# back to the sender of that packet. This will let anyone that
|
|
|
|
# tries to communicate with the destination know whether their
|
|
|
|
# communication was received correctly.
|
|
|
|
destination.set_proof_strategy(RNS.Destination.PROVE_ALL)
|
2024-10-07 08:52:43 +00:00
|
|
|
|
2020-08-13 10:15:56 +00:00
|
|
|
# Everything's ready!
|
|
|
|
# Let's hand over control to the announce loop
|
|
|
|
announceLoop(destination)
|
2020-04-22 10:07:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
def announceLoop(destination):
|
2020-08-13 10:15:56 +00:00
|
|
|
# Let the user know that everything is ready
|
2021-05-17 17:10:11 +00:00
|
|
|
RNS.log(
|
2024-10-07 08:44:18 +00:00
|
|
|
f"Minimal example {RNS.prettyhexrep(destination.hash)} running, hit enter to manually send an announce (Ctrl-C to quit)"
|
2021-05-17 17:10:11 +00:00
|
|
|
)
|
2020-04-22 10:07:13 +00:00
|
|
|
|
2020-08-13 10:15:56 +00:00
|
|
|
# We enter a loop that runs until the users exits.
|
|
|
|
# If the user hits enter, we will announce our server
|
|
|
|
# destination on the network, which will let clients
|
|
|
|
# know how to create messages directed towards it.
|
|
|
|
while True:
|
|
|
|
entered = input()
|
|
|
|
destination.announce()
|
2024-10-07 08:44:18 +00:00
|
|
|
RNS.log(f"Sent announce from {RNS.prettyhexrep(destination.hash)}")
|
2020-04-22 10:07:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
##########################################################
|
|
|
|
#### Program Startup #####################################
|
|
|
|
##########################################################
|
|
|
|
|
|
|
|
# This part of the program gets run at startup,
|
|
|
|
# and parses input from the user, and then starts
|
|
|
|
# the desired program mode.
|
|
|
|
if __name__ == "__main__":
|
2020-08-13 10:15:56 +00:00
|
|
|
try:
|
2021-05-17 17:10:11 +00:00
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description="Minimal example to start Reticulum and create a destination"
|
|
|
|
)
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
"--config",
|
|
|
|
action="store",
|
|
|
|
default=None,
|
|
|
|
help="path to alternative Reticulum config directory",
|
|
|
|
type=str
|
|
|
|
)
|
|
|
|
|
2020-08-13 10:15:56 +00:00
|
|
|
args = parser.parse_args()
|
2020-04-22 10:07:13 +00:00
|
|
|
|
2020-08-13 10:15:56 +00:00
|
|
|
if args.config:
|
|
|
|
configarg = args.config
|
|
|
|
else:
|
|
|
|
configarg = None
|
2020-04-22 10:07:13 +00:00
|
|
|
|
2020-08-13 10:15:56 +00:00
|
|
|
program_setup(configarg)
|
2020-04-22 10:07:13 +00:00
|
|
|
|
2020-08-13 10:15:56 +00:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
print("")
|
|
|
|
exit()
|