Skip to content
Jasper Nalbach edited this page Feb 6, 2017 · 4 revisions

In LAS2peer, users are represented as agents.

Adding user agents using the user agent generator

In order to generate and persist user agent XML description files, one can use the 'UserAgentGenerator' script located in the 'bin' folder. Refer to the Using the Agent Generator Scripts tutorial to learn how the agent XML description files are stored.

Another way is to create an agent after the node has started either in the service code or on the (interactive) command line.

Adding user agents using the interactive command line

Here you do not create an xml file storing the agents' information. On an open node with an interactive command line, you need to execute the following commands to create a user agent.

Stores a user agent with the pass phrase 'Pass' in a variable 'usr':

usr = i5.las2peer.security.UserAgent.createUserAgent('Pass')

The following two commands are optional. The second command gives the user agent a login name, the third one sets an email address. Users are not required to have a login name or email and hence this step is optional. Before changing an agents name, its private key needs to be unlocked. After that, the user

usr.unlockPrivateKey('Pass')
usr.setLoginName('OptionalUserName')
usr.setEmail('user@example.com')

The following command registers the user agent at the node. Here the unlockPrivateKey method gets executed internally, if it was not yet called.

registerUserAgent(usr,'Pass')

Adding user agents in a service method

In order to create a user agent in your service, you need to call the same methods that were invoked on the command line.

UserAgent userAgent = UserAgent.createUserAgent("Pass");
userAgent.unlockPrivateKey("Pass");
userAgent.setLoginName("Name");
userAgent.setEmail(user@example.com");

After the user agent is successfully created, one needs to add it to the currently running node.

Node node = this.getActiveNode();

Finally, the function storeAgent(Agent) is called to upload the user agent to the LAS2peer network. Note, that this function does not register the user agent to this node.

try {
  node.storeAgent(usr); // or node.updateAgent(usr) if an already stored agent should be updated
}
catch(DuplicateEmailException | DuplicateLoginNameException e) {
  // thrown on duplicate
  // in this case, the agent has been stored, but login name and email were not set
  // simply change login name and email and call updateAgent(usr)
}
Clone this wiki locally