Skip to content

Commit

Permalink
RELOAD preliminary JAVA implementation
Browse files Browse the repository at this point in the history
This is a preliminar modular java implementation of RELOAD protocol
from P2PSIP IETF WG. Security and NAT traversal capabilities are not
yet implemented. A lot of bugs remain to be fixed.
  • Loading branch information
imyelmo committed Mar 24, 2015
0 parents commit 955a31c
Show file tree
Hide file tree
Showing 182 changed files with 20,939 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="">
<attributes>
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value=“relod.net/reload/dev2dev/lib"/>
</attributes>
</classpathentry>
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="reload/dev2dev/lib/concurrent.jar"/>
<classpathentry kind="lib" path="reload/dev2dev/lib/jain-sdp-1.0.2337.jar"/>
<classpathentry kind="lib" path="reload/dev2dev/lib/jain-sdp-src-1.0.2337.jar"/>
<classpathentry kind="lib" path="reload/dev2dev/lib/jain-sip-api-1.2-src.jar"/>
<classpathentry kind="lib" path="reload/dev2dev/lib/jain-sip-api-1.2.jar"/>
<classpathentry kind="lib" path="reload/dev2dev/lib/jain-sip-ri-1.2.2337.jar"/>
<classpathentry kind="lib" path="reload/dev2dev/lib/jain-sip-sdp-1.2.2337.jar"/>
<classpathentry kind="lib" path="reload/dev2dev/lib/jain-sip-src-1.2.2337.jar"/>
<classpathentry kind="lib" path="reload/dev2dev/lib/jain-sip-tck-1.2.2337.jar"/>
<classpathentry kind="lib" path="reload/dev2dev/lib/log4j-1.2.17.jar"/>
<classpathentry kind="output" path="trunk/classes"/>
</classpath>
17 changes: 17 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>reload</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
48 changes: 48 additions & 0 deletions reload/Common/AddressType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

package reload.Common;

/* Constructor:
AddressType type = AddressType.valueOf(1);
AddressType type = AddressType.ipv4_address;
*/

public enum AddressType {
UNDEFINED( "undefined", (byte)-1),
reservedAddr("reserved address", (byte)0),
ipv4_address("ipv4 address", (byte)1),
ipv6_address("ipv6 address", (byte)2);


final String name;
final byte value;

private AddressType(String name, byte value) {
this.name = name;
this.value = value;
}


public static AddressType valueOf(int value) {
AddressType type = UNDEFINED;
switch (value) {
case 0:
type = reservedAddr;
break;
case 1:
type = ipv4_address;
break;
case 2:
type = ipv6_address;
break;
}

return type;
}

public byte getBytes(){

return value;

}

}
89 changes: 89 additions & 0 deletions reload/Common/Algorithm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package reload.Common;

import reload.Forwarding.Request.CandType;
import reload.Common.Exception.*;

public class Algorithm{

public static int counter(int size, byte[] data, int sumPosition) throws ReloadException{


if(data.length==0)
return 0;

if(size != 1 && size !=2 && size !=4 && size !=8 && size !=16 && size !=32)
throw new ReloadException("Incorrect size. Only 1, 2 and 4 bytes are allowed. Only 8, 16 and 32 bits are allowed.");

if(size>7)
size=size/8;


int count=0;
int position = sumPosition;

for(boolean salir=false; !salir; count++){

if(size==4)
position += Utils.toInt(data, position)+size;

if(size==2)
position += Utils.toShort(data, position)+size;

if(size==1)
position += data[position]+size;

if(position == data.length)
salir=true;

position += sumPosition;

}

return count;

}


public static int AttachCounter(byte[] data){


if(data.length==0)
return 0;

int position=0;


int count=0;

for(boolean salir=false; !salir; count++){

position += data[position+1]+2; // IPAddresssPort

position++; //OverleyLinkType

position += data[position]+1; // Opaque foundation

position += 4; // int priority

CandType type = CandType.valueOf(data[position]);

position++; // CandType

if (type == CandType.relay)
position += data[position+1]+2; // IPAddresssPort

short ext_length = Utils.toShort(data, position); //short
position += 2;


position += ext_length; // IceExtension[]

if(position == data.length)
salir=true;

}

return count;

}
}
47 changes: 47 additions & 0 deletions reload/Common/DataModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package reload.Common;

/* Constructor:
DataModel type = DataModel.valueOf(1);
DataModel type = DataModel.single_value;
*/

public enum DataModel {
UNDEFINED( "undefined", (byte)-1),
single_value("single value", (byte)1),
array( "array", (byte)2),
dictionary( "dictionary", (byte)3);


final String name;
final byte value;

private DataModel(String name, byte value) {
this.name = name;
this.value = value;
}


public static DataModel valueOf(int value) {
DataModel type = UNDEFINED;
switch (value) {
case 1:
type = single_value;
break;
case 2:
type = array;
break;
case 3:
type = dictionary;
break;
}

return type;
}

public byte getBytes(){

return value;

}

}
106 changes: 106 additions & 0 deletions reload/Common/DataStructure.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@

package reload.Common;

import reload.Storage.Data.DictionaryKey;

public class DataStructure{

private DictionaryKey key; // For Dictionary only
private long storage_time;
private int life_time;
private boolean exists;
private Opaque value;

private boolean dictionary;


public DataStructure(DictionaryKey key, long storage_time, int life_time, boolean exists, Opaque value){

this.key = key;
this.storage_time = storage_time;
this.life_time = life_time;
this.exists = exists;
this.value = value;

dictionary = true;

}

public DataStructure(long storage_time, int life_time, boolean exists, Opaque value){

this.storage_time = storage_time;
this.life_time = life_time;
this.exists = exists;
this.value = value;

dictionary = false;

}

public DataStructure(){ // Empty, exists=false

}

public DictionaryKey getDictionaryKey(){

return key;

}

public long getStorageTime(){

return storage_time;

}

public int getLifeTime(){


return life_time;

}

public boolean getExists(){


return exists;

}

public Opaque getValue(){

return value;

}

public boolean isDictionary(){

return dictionary;

}

public String print(){

String ret = new String();

if(dictionary){
byte[] id = key.getKey();
ret +="0x";
for(int k=0; k<id.length; k++)
ret += String.format("%02x", id[k]);
}

ret += "\t";

byte[] id = value.getContent();
ret +="0x";
for(int k=0; k<id.length; k++)
ret += String.format("%02x", id[k]);

ret += "\n";

return ret;

}

}
12 changes: 12 additions & 0 deletions reload/Common/Error/ErrorDataTooOld.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package reload.Common.Error;


public class ErrorDataTooOld extends ReloadError {

public ErrorDataTooOld() {

super();

}

}
12 changes: 12 additions & 0 deletions reload/Common/Error/ErrorForbidden.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package reload.Common.Error;


public class ErrorForbidden extends ReloadError {

public ErrorForbidden() {

super();

}

}
12 changes: 12 additions & 0 deletions reload/Common/Error/ErrorGenerationCounterTooLow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package reload.Common.Error;


public class ErrorGenerationCounterTooLow extends ReloadError {

public ErrorGenerationCounterTooLow(String ans) {

super(ans);

}

}
12 changes: 12 additions & 0 deletions reload/Common/Error/ErrorNotFound.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package reload.Common.Error;


public class ErrorNotFound extends ReloadError {

public ErrorNotFound() {

super();

}

}
Loading

0 comments on commit 955a31c

Please sign in to comment.