Skip to content

Starting A las2peer Network

Navid RahimiDanesh edited this page Apr 27, 2021 · 5 revisions

This tutorial will guide you through the process of starting your first las2peer network. It is highly recommended that you read the step by step First Service tutorial first to have an idea of how to build your service. This tutorial builds up on it. It is split into two parts: The first part explains the build up of a las2peer instance, giving you some insight into how you can configure your node. The second part deals with starting a las2peer node with the L2pNodeLauncher.

Build-Up of a las2peer Instance

After having successfully completed the first tutorial, you should have a las2peer instance that is ready to run. It should look something like this:

calculateRectangleAreaInvokeCmd

To give you an insight into the configuration of a las2peer instance, let us take a look at the different directories:

The bin Directory

This directory contains a start script that is used in the second part of this tutorial and two agent generator scripts. The agent generator scripts are used to create agent XML files that are stored in the etc directory. This directory is thus not directly necessary for running a las2peer instance, but the scripts ease the handling.

The etc Directory

This directory contains all configuration files.

  • The nodeInfo.xml file contains some information about the node that can be requested by everybody. Currently, it contains a mail and description field that can be filled arbitrary.
  • The second file in the directory is a property file of the Web-Connector. These property files can be created for each service or connector. Just add a new file, named according to your service package, to this directory and the line setFieldValues() to the constructor of your main services class. By adding the annotation @ManualDeployment to your service class the use of property files is enabled and las2peer will read this file at your service startup. If your service contains a global variable named the same as a variable specified in the configuration file of your service, it will be set to the value of your configuration file. Take a look at the connector`s configuration file for the syntax.
  • There is also a directory called startup. Everything in here can be loaded into a las2peer network by passing the command uploadStartupDirectory to the L2pNodeLauncher. Currently, it should hold agent definitions for a couple of users agent that are generated by the gradle build script. The third file is called passphrases.txt and contains the passphrases needed to unlock these agents (for uploading). It is also generated by the build script.
The lib Directory

This directory contains the libraries needed to start a las2peer network. It is created (and filled) by the gradle script.

The log Directory

This is the default directory for all log files.

The service Directory

This is the default directory for all services. It should contain your service jar, since the gradle script puts it there automatically (apart from adding it to the export directory).

Other Directories

You might also recognize some additional folders. The .las2peer folder is used by a las2peer instance for storing (encrypted) content of the network. You can think of it as the storage of a node. After a node shuts down, this content is not deleted, but you can not access it anymore. So after a node has shut down, you can delete the corresponding (sub-)directory if you want. The export folder contains your service Jar and the documentation generated from your source code. You can also find your test reports there. As well as the tmp and .settings directories (and the other files located at the root directory), these folders are not used by a las2peer instance itself, but are rather part of your project configuration. You can delete them if you just want to deploy a node somewhere.

Starting a las2peer Node / Network

Now that you have configured your node, you can start it with the start_network script in your bin directory.

./bin/start_network.sh

The last line of this script looks like the following:

java -cp "lib/*" i5.las2peer.tools.L2pNodeLauncher -s service -p PORT {additional commands} interactive

This will execute your system's default java. Make sure it is java 14

By running this, a new network will start with one node listening on PORT (so make sure the port is open) and you enter the interactive mode which allows you to further execute commands on the node.

You can change options to suit your requirements (see the L2pNodeLauncher tutorial for more information on this topic)
Here are some examples:

  1. Start a new network with your node starting at port 9001:

    [..] i5.las2peer.tools.L2pNodeLauncher -s service -p 9001
    
  2. Add an additional node to your network at port 9002 and enter the interactive mode:

    [..] i5.las2peer.tools.L2pNodeLauncher -s service -p 9002 -b YOUR_IP:9001 interactive
    

YOUR_IP should be your actual ip (not localhost or 127.0.0.1)

Each started node will continue to run if the last command is not the shutdown command.

You can stop the complete run using Ctrl-C at any point.

You can find detailed log files for each node in the directory log/ afterwards.

To end this tutorial, here is a list of commands that can be executed at a node in interactive mode to start and use the service we developed in the tutorials (please note that you might have to slightly adjust the user and method names according to the ones you chose). If you use the start script in the bin directory to start the node, the first two commands will already be executed and do not have to be repeated:

uploadStartupDirectory
startService('i5.las2peer.services.myNewService.MyNewServiceMainClass@1.0', 'someNewPass')
registerUserAgent('UserA', 'userAPass')
invoke('i5.las2peer.services.myNewService.MyNewServiceMainClass', 'validateLogin', '')
invoke('i5.las2peer.services.myNewService.MyNewServiceMainClass', 'exampleMethod', 'What a beautiful service!')

The result should look something like this (open in new window):

calculateRectangleAreaInvokeCmd

For more information about the L2pNodeLauncher and its usage, please visit the L2pNodeLauncher Tutorial.

Clone this wiki locally