Skip to content

Commit

Permalink
Merge pull request #13 from rwth-acis/development
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
derjasper committed May 17, 2016
2 parents 341b5a1 + d93bee0 commit 5d3b123
Show file tree
Hide file tree
Showing 28 changed files with 980 additions and 404 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/output
/export
/node-storage
/.las2peer
/tmp
/log
/lib
/ivy/ivy.jar
ivy.jar
/service
/out
/.idea
*.iml
/.las2peer
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
![las2peer](https://github.com/rwth-acis/LAS2peer/blob/master/img/logo/bitmap/las2peer-logo-128x128.png)
![las2peer](https://github.com/rwth-acis/las2peer/blob/master/img/logo/bitmap/las2peer-logo-128x128.png)

las2peer is a Java-based server framework for developing and deploying services in a distributed Peer-to-Peer (P2P) environment. las2peer was developed by the Advanced Community Information Systems (ACIS) group at the Chair of Computer Science 5 (Information Systems & Databases), RWTH Aachen University, Germany. It's main focus lies on providing developers with a tool to easily develop and test their services and deploy them in a P2P network without having to rely on a centralized infrastructure.

Developers can develop and test their services locally and then deploy them on any machine that has joined the network. For communication between nodes, the FreePastry (http://www.freepastry.org/) library is used.

Currently, connection to the outside is realized via the [HTTP-Connector](https://github.com/rwth-acis/LAS2peer-HttpConnector/) or the [Web-Connector](https://github.com/rwth-acis/LAS2peer-WebConnector/).
Currently, connection to the outside is realized via the [HTTP-Connector](https://github.com/rwth-acis/las2peer-HttpConnector/) or the [Web-Connector](https://github.com/rwth-acis/las2peer-WebConnector/).

Service Development
-----------------------
This project contains las2peer itself. To develop a service for las2peer, please use the
[las2peer Template Project](https://github.com/rwth-acis/LAS2peer-Template-Project/) and follow the instructions of the project's ReadMe.
[las2peer Template Project](https://github.com/rwth-acis/las2peer-Template-Project/) and follow the instructions of the project's ReadMe.

If you want to learn more about las2peer, please visit the [las2peer Template Project's Wiki Page](https://github.com/rwth-acis/LAS2peer-Template-Project/wiki).
If you want to learn more about las2peer, please visit the [las2peer Template Project's Wiki Page](https://github.com/rwth-acis/las2peer-Template-Project/wiki).

Preparations
-----------------------
Expand All @@ -34,9 +34,9 @@ To build the las2peer jar file simply run default target:
or directly
```ant jars```

Jenkins: [![Build Status](http://layers.dbis.rwth-aachen.de/jenkins/buildStatus/icon?job=LAS2peer Core)](http://layers.dbis.rwth-aachen.de/jenkins/job/LAS2peer%20Core/)
Jenkins: [![Build Status](http://layers.dbis.rwth-aachen.de/jenkins/buildStatus/icon?job=las2peer Core)](http://layers.dbis.rwth-aachen.de/jenkins/job/las2peer%20Core/)

Travis CI: [![Build Status](https://travis-ci.org/rwth-acis/LAS2peer.svg?branch=master)](https://travis-ci.org/rwth-acis/LAS2peer)
Travis CI: [![Build Status](https://travis-ci.org/rwth-acis/las2peer.svg?branch=master)](https://travis-ci.org/rwth-acis/las2peer)

JUnit Tests
-----------
Expand Down
7 changes: 5 additions & 2 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<property name="ivy.organisation" value="i5" />
<property name="ivy.module" value="las2peer" />
<property name="ivy.revision" value="0.5" />
<property name="ivy.build.number" value="1" />
<property name="ivy.build.number" value="2" />
<property name="ivy.deliver.revision" value="${ivy.revision}" />
<property name="ivy.pom.version" value="${ivy.revision}" />

Expand Down Expand Up @@ -324,6 +324,7 @@
<fileset dir="${tmp.classes}">
<exclude name="i5/las2peer/testing/services/**" />
</fileset>
<fileset file="etc/las2peer.policy" />
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
<attribute name="Class-Path" value="${classpath.name}" />
Expand Down Expand Up @@ -414,10 +415,12 @@
<pathelement path="${lib.cp}" />
<pathelement path="${lib.junit}" />
</classpath>
<formatter type="plain" />
<formatter type="plain" usefile="false" />
<formatter type="plain" />
<batchtest fork="yes" todir="${junit.report}">
<fileset dir="${tmp.junit}">
<include name="**/*Test.class"/>
<exclude name="**/SandboxTest.class"/>
</fileset>
</batchtest>
</junit>
Expand Down
59 changes: 59 additions & 0 deletions etc/las2peer.policy
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// This is the policy file used for las2peer sandboxing.
// If you want a service to have access to the file system or
// open network ports add the respective rights below.

// THE SANDBOX IS DISABLED BY DEFAULT!
// If you want to deploy las2peer it's strongly recommended to comment out or delete the following lines.
// This enables sandboxing and protects your system from malicious file access and networking operations.
// If you experience issues please check the logs for blocked permissions and whitelist them in this file.
grant {
permission java.security.AllPermission;
};

// example: This entry gives read and write access to a local directory called 'localdir'
// in your LAS2peer installation directory.
//grant {
// permission java.io.FilePermission "localdir", "read, write"; // the directory itself
// permission java.io.FilePermission "localdir${/}-", "read, write"; // all files and subdirectories inside
//};

// las2peer related files
grant {
// las2peer file read permissions
permission java.io.FilePermission "etc", "read";
permission java.io.FilePermission "etc${/}-", "read";
permission java.io.FilePermission "config", "read";
permission java.io.FilePermission "config${/}-", "read";
permission java.io.FilePermission "properties", "read";
permission java.io.FilePermission "properties${/}-", "read";
permission java.io.FilePermission "lib", "read";
permission java.io.FilePermission "lib${/}-", "read";
permission java.io.FilePermission "service", "read";
permission java.io.FilePermission "service${/}-", "read";

// las2peer file write permissions
permission java.io.FilePermission "log", "read, write";
permission java.io.FilePermission "log${/}-", "read, write";
permission java.io.FilePermission "node-storage", "read, write, delete";
permission java.io.FilePermission "node-storage${/}-", "read, write, delete";

// las2peer network permissions
// allow local ports from 8000 to 9999 to be used as server ports
permission java.net.SocketPermission "localhost:8000-9999", "listen";
// the following portrange is reserved for JUnit tests
permission java.net.SocketPermission "localhost:14500-14599", "listen";
// allow connections to any remote host
permission java.net.SocketPermission "*", "connect,accept";
};

// Linux system file permissions
grant {
permission java.io.FilePermission "/dev/random", "read";
permission java.io.FilePermission "/dev/urandom", "read";
};

// pastry permissions
grant {
permission java.io.FilePermission "${java.io.tmpdir}", "read";
permission java.io.FilePermission "user.params", "read";
};
16 changes: 11 additions & 5 deletions src/main/java/i5/las2peer/api/Configurable.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ protected void setFieldValues() {
* contains the value for the monitoring switch and sets it if so.
*
* All fields mentioned in <i>except</i> will be left out.
* @param except
* @param except
*
*/
protected void setFieldValues(Set<String> except) {
Expand Down Expand Up @@ -246,11 +246,17 @@ protected void setFieldValues(Set<String> except) {
*/
private String findPropertyFile() {
String filename = getClass().getName() + ".properties";
String[] testDirs = new String[] { "./", "config/", "etc/", "properties/" };
String[] testDirs = new String[] { "config/", "etc/", "properties/" };

for (String dir : testDirs)
if (new File(dir + filename).exists())
return dir + filename;
for (String dir : testDirs) {
try {
if (new File(dir + filename).exists()) {
return dir + filename;
}
} catch (Exception e) {
// XXX logging
}
}

return null;
}
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/i5/las2peer/api/Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,6 @@ public Object execute(String method, Object... parameters) throws NoSuchServiceM
IllegalArgumentException, IllegalAccessException, InvocationTargetException, L2pSecurityException {
Method m = searchMethod(method, parameters);

// TODO make sure that main agent is unlocked?

return m.invoke(this, parameters);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ public Class<?> getServiceClass(String serviceClassName) throws ClassLoaderExcep
} catch (LibraryNotFoundException e) {
// class could not be found in any registered library, try default classpath
// this is usually the case when executed within an IDE
System.err.println("No library found for " + serviceClassName
System.err.println("Warning! No library (jar) found for " + serviceClassName
+ "! Trying default classpath. This should not happen in a productive environment!");
try {
return this.getClass().getClassLoader().loadClass(serviceClassName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class FileSystemRepository implements Repository {
private Iterable<String> directories;
private boolean recursive = false;
private Hashtable<String, Hashtable<LibraryVersion, String>> htFoundJars;
private long lastModified = 0;

/**
* create a repository for the given directory, non-recursive
Expand Down Expand Up @@ -77,7 +78,7 @@ public FileSystemRepository(Iterable<String> directories, boolean recursive) {
this.directories = directories;
this.recursive = recursive;

initJarList();
updateRepository(true);
}

/**
Expand All @@ -89,6 +90,8 @@ public FileSystemRepository(Iterable<String> directories, boolean recursive) {
* @throws UnresolvedDependenciesException
*/
public LoadedLibrary findLibrary(String name) throws LibraryNotFoundException, UnresolvedDependenciesException {
updateRepository(false);

Hashtable<LibraryVersion, String> htVersions = htFoundJars.get(name);
if (htVersions == null) {
System.err.println(this + " could not find " + name);
Expand Down Expand Up @@ -126,6 +129,8 @@ public LoadedLibrary findLibrary(String name) throws LibraryNotFoundException, U
* @throws LibraryNotFoundException
*/
public LoadedLibrary findLibrary(LibraryIdentifier lib) throws LibraryNotFoundException {
updateRepository(false);

Hashtable<LibraryVersion, String> htVersions = htFoundJars.get(lib.getName());
if (htVersions == null)
throw new LibraryNotFoundException(
Expand Down Expand Up @@ -153,6 +158,8 @@ public LoadedLibrary findLibrary(LibraryIdentifier lib) throws LibraryNotFoundEx
* @throws LibraryNotFoundException
*/
public LoadedLibrary findMatchingLibrary(LibraryDependency dep) throws LibraryNotFoundException {
updateRepository(false);

Hashtable<LibraryVersion, String> htVersions = htFoundJars.get(dep.getName());
if (htVersions == null)
throw new LibraryNotFoundException(
Expand Down Expand Up @@ -230,6 +237,54 @@ public Collection<String> getLibraryCollection() {

return hsTemp;
}

/**
* helper method to get the last modification date of a directory
* @param dir
* @param recursive
* @return
* */
public static long getLastModified(File dir, boolean recursive) {
File[] files = dir.listFiles();
if (files == null || files.length == 0) {
return dir.lastModified();
}

long lastModified = 0;
for (File f : files) {
if (f.isDirectory() && recursive) {
long ll = getLastModified(f, recursive);
if (lastModified < ll) {
lastModified = ll;
}
}
else {
if (lastModified < f.lastModified()) {
lastModified = f.lastModified();
}
}
}
return lastModified;
}

/**
* checks if there were changes made in the folder and re-reads repositories if so
* @param force if true, the repository will be updated independent from last modification
*/
private void updateRepository(boolean force) {
long currentLastModified = 0;
for (String directory : directories) {
long ll = getLastModified(new File(directory), recursive);
if (currentLastModified < ll) {
currentLastModified = ll;
}
}

if (lastModified < currentLastModified || force) {
lastModified = currentLastModified;
initJarList();
}
}

/**
* initialize the list if jars
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/i5/las2peer/communication/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
*/
public class Message implements XmlAble {

public static final long DEFAULT_TIMEOUT = 3600 * 1000; // 1 hour
public static final long DEFAULT_TIMEOUT = 30 * 1000; // 30 seconds

/**
* sender of the message
Expand Down Expand Up @@ -86,14 +86,14 @@ public class Message implements XmlAble {
private byte[] baContentKey;

/**
* time stamp of the message generation
* timestamp of the message generation
*/
private long timestampMs;

/**
* how long in milliseconds is this message valid (time stamp of timeout is time stamp + validMs)
* how long in milliseconds is this message valid (timestamp of timeout is timestamp + validMs)
*/
private long validMs = DEFAULT_TIMEOUT;
private long validMs;

/**
* a simple message id for reference, i.e. answer messages
Expand Down Expand Up @@ -613,7 +613,7 @@ public long getTimestamp() {
}

/**
* @return time stamp of message creation as Date object
* @return timestamp of message creation as Date object
*/
public Date getTimestampDate() {
return new Date(timestampMs);
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/i5/las2peer/logging/L2pLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,14 @@ public static void logEvent(Event event, String message) {
* @param message
*/
public static void logEvent(Event event, Agent actingUser, String message) {
logEvent(null, event, message, null, actingUser);
Thread t = Thread.currentThread();
if (t instanceof L2pThread) {
// Logging custom service messages requires a serviceAgent
Agent serviceAgent = ((L2pThread) t).getServiceAgent();
logEvent(null, event, message, serviceAgent, actingUser);
} else {
throw new IllegalStateException("Not executed in a L2pThread environment!");
}
}

/**
Expand Down
20 changes: 0 additions & 20 deletions src/main/java/i5/las2peer/p2p/LocalNode.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package i5.las2peer.p2p;

import java.security.PublicKey;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Random;
Expand All @@ -16,7 +15,6 @@
import i5.las2peer.security.L2pSecurityException;
import i5.las2peer.security.MessageReceiver;
import i5.las2peer.security.UserAgent;
import i5.las2peer.tools.CryptoTools;
import i5.las2peer.tools.SerializationException;
import i5.las2peer.tools.TimerThread;

Expand Down Expand Up @@ -273,24 +271,6 @@ public NodeInformation getNodeInformation(Object nodeId) throws NodeNotFoundExce
}
}

@Override
public void sendUnlockRequest(long agentId, String passphrase, Object targetNode, PublicKey nodeEncryptionKey)
throws L2pSecurityException {

if (!(targetNode instanceof Long))
throw new IllegalArgumentException(
"node id is not a Long value but a " + targetNode.getClass().getName() + "(" + targetNode + ")");

try {
byte[] encPass = CryptoTools.encryptAsymmetric(passphrase, nodeEncryptionKey);
getNode((Long) targetNode).unlockRemoteAgent(agentId, encPass);

} catch (Exception e) {
throw new L2pSecurityException("unable to unlock agent at node " + targetNode);
}

}

/************************** factories ***************************************/

/**
Expand Down
Loading

0 comments on commit 5d3b123

Please sign in to comment.