Skip to content

Commit

Permalink
Rebase master JPAN
Browse files Browse the repository at this point in the history
  • Loading branch information
Tilmann Zäschke committed Apr 17, 2024
1 parent ca88014 commit 6894173
Show file tree
Hide file tree
Showing 15 changed files with 79 additions and 91 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/scion/jpan/ScionService.java
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ List<Daemon.Path> getPathListDaemon(long srcIsdAs, long dstIsdAs) {
*/
public List<RequestPath> getPaths(InetSocketAddress dstAddress) throws IOException {
ScionAddress sa = getScionAddress(dstAddress.getHostName());
return getPaths(sa.getIsdAs(), sa.getInetAddress().getAddress(), dstAddress.getPort());
return getPaths(sa.getIsdAs(), sa.getInetAddress(), dstAddress.getPort());
}

/**
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/org/scion/jpan/internal/AddressResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package org.scion.internal;
package org.scion.jpan.internal;

import java.net.InetAddress;
import org.scion.ScionAddress;
import org.scion.ScionException;
import org.scion.ScionService;

import org.scion.internal.SimpleCache;
import org.scion.jpan.ScionAddress;
import org.scion.jpan.ScionException;
import org.scion.jpan.ScionService;

public class AddressResolver {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package org.scion.socket;
package org.scion.jpan.socket;

import java.io.IOException;
import java.io.UncheckedIOException;
Expand All @@ -26,14 +26,14 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.scion.*;
import org.scion.jpan.*;
import org.scion.internal.SimpleCache;

/**
* A DatagramSocket that is SCION path aware. It can send and receive SCION packets.
*
* <p>Note: use of this class is discouraged in favor of org.scion.{@link
* org.scion.DatagramChannel}. The reason is that this class' API (InetAddress and DatagramPacket)
* org.scion.jpan.DatagramChannel}. The reason is that this class' API (InetAddress and DatagramPacket)
* cannot be extended to support SCION paths. As a consequence, a server needs to cache paths
* internally which requires memory and may cause exceptions if more connections (=paths) are
* managed than the configured thresholds allows.
Expand Down Expand Up @@ -250,11 +250,7 @@ public int getPort() {

@Override
public SocketAddress getRemoteSocketAddress() {
try {
return channel.getRemoteAddress();
} catch (UnknownHostException e) {
throw new ScionRuntimeException(e);
}
return channel.getRemoteAddress();
}

@Override
Expand Down Expand Up @@ -322,14 +318,14 @@ public synchronized void receive(DatagramPacket packet) throws IOException {
}
if (!channel.isConnected()) {
synchronized (pathCache) {
InetAddress ip = InetAddress.getByAddress(path.getDestinationAddress());
InetAddress ip = path.getDestinationAddress();
InetSocketAddress addr = new InetSocketAddress(ip, path.getDestinationPort());
pathCache.put(addr, path);
}
}
receiveBuffer.flip();
packet.setLength(receiveBuffer.limit());
packet.setAddress(InetAddress.getByAddress(path.getDestinationAddress()));
packet.setAddress(path.getDestinationAddress());
packet.setPort(path.getDestinationPort());
}
}
Expand Down Expand Up @@ -545,7 +541,7 @@ public synchronized int getPathCacheCapacity() {
* implemented.
*/
@Deprecated
public synchronized org.scion.DatagramChannel getScionChannel() {
public synchronized org.scion.jpan.DatagramChannel getScionChannel() {
return channel;
}

Expand All @@ -564,11 +560,11 @@ public synchronized void setPathPolicy(PathPolicy pathPolicy) throws IOException
/**
* Assume that the destination host uses a dispatcher.
*
* <p>See {@link org.scion.DatagramChannel#configureRemoteDispatcher(boolean)}.
* <p>See {@link org.scion.jpan.DatagramChannel#configureRemoteDispatcher(boolean)}.
*
* @param hasDispatcher Set to 'true' if remote end-host uses a dispatcher and requires using port
* 30041.
* @see org.scion.DatagramChannel#configureRemoteDispatcher(boolean)
* @see org.scion.jpan.DatagramChannel#configureRemoteDispatcher(boolean)
* @deprecated To be remove once dispatchers have been removed
*/
@Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package org.scion.socket;
package org.scion.jpan.socket;

import java.io.IOException;
import java.net.InetSocketAddress;
Expand All @@ -21,17 +21,17 @@
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.util.Iterator;
import org.scion.ResponsePath;
import org.scion.ScionService;
import org.scion.internal.InternalConstants;
import org.scion.internal.ScionHeaderParser;
import org.scion.jpan.ResponsePath;
import org.scion.jpan.ScionService;
import org.scion.jpan.internal.InternalConstants;
import org.scion.jpan.internal.ScionHeaderParser;

/**
* DatagramChannel with support for timeout.
*
* <p>The class is non-public for now. It may be removed (or not) once we implement Selectors.
*/
class SelectingDatagramChannel extends org.scion.DatagramChannel {
class SelectingDatagramChannel extends org.scion.jpan.DatagramChannel {
private final Selector selector;
private int timeoutMs = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,24 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package org.scion.api;
package org.scion.jpan.api;

import static org.junit.jupiter.api.Assertions.*;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.*;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.scion.*;
import org.scion.internal.MultiMap;
import org.scion.jpan.*;
import org.scion.jpan.socket.DatagramSocket;

class DatagramSocketApiCompletenessTest {

@Test
void testApiCompleteness() {
// Test that org.scion.DatagramSocket overrides ALL methods of java.net.DatagramSocket
MultiMap<String, Method> methods = new MultiMap<>();
for (Method m : org.scion.socket.DatagramSocket.class.getDeclaredMethods()) {
for (Method m : DatagramSocket.class.getDeclaredMethods()) {
methods.put(m.getName(), m);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
import static org.junit.jupiter.api.Assertions.*;

import java.io.IOException;
import java.net.*;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
Expand All @@ -26,10 +29,10 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.scion.*;
import org.scion.socket.DatagramSocket;
import org.scion.testutil.MockDNS;
import org.scion.testutil.MockDaemon;
import org.scion.jpan.*;
import org.scion.jpan.testutil.MockDNS;
import org.scion.jpan.testutil.MockDaemon;
import org.scion.jpan.socket.DatagramSocket;

class DatagramSocketApiConcurrencyTest {

Expand Down
36 changes: 12 additions & 24 deletions src/test/java/org/scion/jpan/api/DatagramSocketApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package org.scion.api;
package org.scion.jpan.api;

import static org.junit.jupiter.api.Assertions.*;

Expand All @@ -33,22 +33,15 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.scion.PackageVisibilityHelper;
import org.scion.Path;
import org.scion.PathPolicy;
import org.scion.RequestPath;
import org.scion.Scion;
import org.scion.ScionAddress;
import org.scion.ScionService;
import org.scion.ScionSocketOptions;
import org.scion.proto.daemon.Daemon;
import org.scion.socket.DatagramSocket;
import org.scion.testutil.ExamplePacket;
import org.scion.testutil.MockDNS;
import org.scion.testutil.MockDaemon;
import org.scion.testutil.MockNetwork;
import org.scion.testutil.PingPongSocketHelper;
import org.scion.testutil.Util;
import org.scion.jpan.*;
import org.scion.jpan.proto.daemon.Daemon;
import org.scion.jpan.socket.DatagramSocket;
import org.scion.jpan.testutil.ExamplePacket;
import org.scion.jpan.testutil.MockDNS;
import org.scion.jpan.testutil.MockDaemon;
import org.scion.jpan.testutil.MockNetwork;
import org.scion.jpan.testutil.PingPongSocketHelper;
import org.scion.jpan.testutil.Util;

class DatagramSocketApiTest {

Expand Down Expand Up @@ -312,7 +305,7 @@ void isConnected_InetSocket() throws IOException {
@Test
void isConnected_Path() throws IOException {
RequestPath path = PackageVisibilityHelper.createDummyPath();
InetAddress ip = InetAddress.getByAddress(path.getDestinationAddress());
InetAddress ip = path.getDestinationAddress();
InetSocketAddress address = new InetSocketAddress(ip, path.getDestinationPort());
try (DatagramSocket socket = new DatagramSocket()) {
assertFalse(socket.isConnected());
Expand Down Expand Up @@ -663,12 +656,7 @@ private RequestPath createExpiredPath(Path basePath) throws UnknownHostException
}

private static InetSocketAddress toAddress(Path path) {
try {
InetAddress ip = InetAddress.getByAddress(path.getDestinationAddress());
return new InetSocketAddress(ip, path.getDestinationPort());
} catch (UnknownHostException e) {
throw new RuntimeException(e);
}
return new InetSocketAddress(path.getDestinationAddress(), path.getDestinationPort());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package org.scion.api;
package org.scion.jpan.api;

import static org.junit.jupiter.api.Assertions.*;
import static org.scion.testutil.PingPongHelperBase.MSG;
import static org.scion.jpan.testutil.PingPongHelperBase.MSG;

import java.io.IOException;
import java.net.*;
Expand All @@ -24,11 +24,11 @@
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.scion.RequestPath;
import org.scion.ScionService;
import org.scion.socket.DatagramSocket;
import org.scion.testutil.MockNetwork;
import org.scion.testutil.PingPongSocketHelper;
import org.scion.jpan.RequestPath;
import org.scion.jpan.ScionService;
import org.scion.jpan.socket.DatagramSocket;
import org.scion.jpan.testutil.MockNetwork;
import org.scion.jpan.testutil.PingPongSocketHelper;

class DatagramSocketConcurrentPingPongTest {

Expand Down Expand Up @@ -63,7 +63,7 @@ void test() throws IOException {

private void client(DatagramSocket socket, RequestPath requestPath, int id) throws IOException {
byte[] sendBuf = MSG.getBytes();
InetAddress addr = InetAddress.getByAddress(requestPath.getDestinationAddress());
InetAddress addr = requestPath.getDestinationAddress();
int port = requestPath.getDestinationPort();
DatagramPacket request = new DatagramPacket(sendBuf, sendBuf.length, addr, port);
socket.send(request);
Expand Down
16 changes: 8 additions & 8 deletions src/test/java/org/scion/jpan/api/DatagramSocketPingPongTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package org.scion.api;
package org.scion.jpan.api;

import static org.junit.jupiter.api.Assertions.*;
import static org.scion.testutil.PingPongHelperBase.MSG;
import static org.scion.jpan.testutil.PingPongHelperBase.MSG;

import java.io.IOException;
import java.net.*;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import org.scion.RequestPath;
import org.scion.ScionService;
import org.scion.socket.DatagramSocket;
import org.scion.testutil.MockNetwork;
import org.scion.testutil.PingPongSocketHelper;
import org.scion.jpan.RequestPath;
import org.scion.jpan.ScionService;
import org.scion.jpan.socket.DatagramSocket;
import org.scion.jpan.testutil.MockNetwork;
import org.scion.jpan.testutil.PingPongSocketHelper;

class DatagramSocketPingPongTest {

Expand All @@ -46,7 +46,7 @@ void test() {

private void client(DatagramSocket socket, RequestPath requestPath, int id) throws IOException {
byte[] sendBuf = MSG.getBytes();
InetAddress addr = InetAddress.getByAddress(requestPath.getDestinationAddress());
InetAddress addr = requestPath.getDestinationAddress();
int port = requestPath.getDestinationPort();
DatagramPacket request = new DatagramPacket(sendBuf, sendBuf.length, addr, port);
socket.send(request);
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/scion/jpan/demo/PingPongSocketClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package org.scion.demo;
package org.scion.jpan.demo;

import java.io.IOException;
import java.net.*;
import org.scion.socket.DatagramSocket;
import org.scion.testutil.MockDNS;
import org.scion.jpan.socket.DatagramSocket;
import org.scion.jpan.testutil.MockDNS;

public class PingPongSocketClient {

Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/scion/jpan/demo/PingPongSocketDemoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package org.scion.demo;
package org.scion.jpan.demo;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.scion.ScionService;
import org.scion.testutil.MockDNS;
import org.scion.jpan.ScionService;
import org.scion.jpan.testutil.MockDNS;

public class PingPongSocketDemoTest {

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/scion/jpan/demo/PingPongSocketServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package org.scion.demo;
package org.scion.jpan.demo;

import java.io.*;
import java.net.*;
import org.scion.socket.DatagramSocket;
import org.scion.jpan.socket.DatagramSocket;

public class PingPongSocketServer {

Expand Down
Loading

0 comments on commit 6894173

Please sign in to comment.