#7 implement lookup with decentralized naming service
This commit is contained in:
parent
95c2d445a7
commit
d6437cef33
@ -71,11 +71,15 @@ public class NameServerRemote implements INameserverRemote, Serializable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public INameserverRemote getNameserver(String zone) throws RemoteException {
|
public INameserverRemote getNameserver(String zone) throws RemoteException {
|
||||||
return null;
|
// System.out.printf("NameServer %s DNS Lookup getNameserver()%n", name);
|
||||||
|
// System.out.println(this.getNameservers());
|
||||||
|
return subdomains.get(zone);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String lookup(String username) throws RemoteException {
|
public String lookup(String username) throws RemoteException {
|
||||||
return null;
|
// System.out.printf("NameServer %s DNS Lookup lookup() for %s%n", name, username);
|
||||||
|
// System.out.println(this.getAddresses());
|
||||||
|
return addresses.get(username);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,12 @@ package dslab.transfer;
|
|||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
|
import java.rmi.NotBoundException;
|
||||||
|
import java.rmi.RemoteException;
|
||||||
|
import java.rmi.registry.LocateRegistry;
|
||||||
|
import java.rmi.registry.Registry;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.BlockingQueue;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
@ -16,6 +21,9 @@ import dslab.Email;
|
|||||||
import dslab.Message;
|
import dslab.Message;
|
||||||
import dslab.exception.MalformedInputException;
|
import dslab.exception.MalformedInputException;
|
||||||
import dslab.exception.UnknownDomainException;
|
import dslab.exception.UnknownDomainException;
|
||||||
|
import dslab.nameserver.AlreadyRegisteredException;
|
||||||
|
import dslab.nameserver.INameserverRemote;
|
||||||
|
import dslab.nameserver.InvalidDomainException;
|
||||||
import dslab.util.Config;
|
import dslab.util.Config;
|
||||||
|
|
||||||
public class TransferServer implements ITransferServer, Runnable {
|
public class TransferServer implements ITransferServer, Runnable {
|
||||||
@ -44,7 +52,7 @@ public class TransferServer implements ITransferServer, Runnable {
|
|||||||
String monitoringHost = config.getString("monitoring.host");
|
String monitoringHost = config.getString("monitoring.host");
|
||||||
Integer monitoringPort = config.getInt("monitoring.port");
|
Integer monitoringPort = config.getInt("monitoring.port");
|
||||||
this.serverPort = config.getInt("tcp.port");
|
this.serverPort = config.getInt("tcp.port");
|
||||||
this.consumer = new Consumer(mailboxServers, monitoringHost, monitoringPort, "127.0.0.1", this.serverPort);
|
this.consumer = new Consumer(mailboxServers, monitoringHost, monitoringPort, "127.0.0.1", this.serverPort, config);
|
||||||
this.shell = new Shell(in, out);
|
this.shell = new Shell(in, out);
|
||||||
this.shell.register(this);
|
this.shell.register(this);
|
||||||
this.shell.setPrompt("Transferserver> ");
|
this.shell.setPrompt("Transferserver> ");
|
||||||
@ -124,16 +132,30 @@ public class TransferServer implements ITransferServer, Runnable {
|
|||||||
private final String transferHost;
|
private final String transferHost;
|
||||||
private final Integer transferPort;
|
private final Integer transferPort;
|
||||||
|
|
||||||
|
private Registry registry;
|
||||||
|
private INameserverRemote nameserverRemote;
|
||||||
|
|
||||||
Consumer(HashMap<String, Integer> mailboxServers,
|
Consumer(HashMap<String, Integer> mailboxServers,
|
||||||
String monitoringHost,
|
String monitoringHost,
|
||||||
Integer monitoringPort,
|
Integer monitoringPort,
|
||||||
String transferHost,
|
String transferHost,
|
||||||
Integer transferPort) {
|
Integer transferPort,
|
||||||
|
Config config) {
|
||||||
this.mailboxServers = mailboxServers;
|
this.mailboxServers = mailboxServers;
|
||||||
this.monitoringHost = monitoringHost;
|
this.monitoringHost = monitoringHost;
|
||||||
this.monitoringPort = monitoringPort;
|
this.monitoringPort = monitoringPort;
|
||||||
this.transferHost = transferHost;
|
this.transferHost = transferHost;
|
||||||
this.transferPort = transferPort;
|
this.transferPort = transferPort;
|
||||||
|
// registry
|
||||||
|
String registryName = config.getString("root_id");
|
||||||
|
String registryHost = config.getString("registry.host");
|
||||||
|
int registryPort = config.getInt("registry.port");
|
||||||
|
try {
|
||||||
|
registry = LocateRegistry.getRegistry(registryHost, registryPort);
|
||||||
|
nameserverRemote = (INameserverRemote) registry.lookup(registryName);
|
||||||
|
} catch (RemoteException | NotBoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -212,11 +234,32 @@ public class TransferServer implements ITransferServer, Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int domainLookup(Email email) throws UnknownDomainException {
|
private int domainLookup(Email email) throws UnknownDomainException {
|
||||||
logger.info("Performing domain lookup for address " + email.toString());
|
String domain = email.getDomain();
|
||||||
if (this.mailboxServers.containsKey(email.getDomain()))
|
logger.info("Search for domain " + domain);
|
||||||
return this.mailboxServers.get(email.getDomain());
|
String[] domainParts = domain.split("\\.");
|
||||||
|
System.out.println(Arrays.toString(domainParts));
|
||||||
|
INameserverRemote zone = nameserverRemote;
|
||||||
|
for (int i = domainParts.length - 1; i > 0; i--) {
|
||||||
|
logger.info("Step " + i);
|
||||||
|
try {
|
||||||
|
logger.info("Get zone " + domainParts[i]);
|
||||||
|
zone = zone.getNameserver(domainParts[i]);
|
||||||
|
logger.info("Got zone!");
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
logger.severe("DNS Issue: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// in the last step, call lookup
|
||||||
|
try {
|
||||||
|
String address = zone.lookup(domainParts[0]);
|
||||||
|
logger.info("Found address " + address);
|
||||||
|
return Integer.parseInt(address.split(":")[1]); // take only port
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
e.printStackTrace();
|
||||||
throw new UnknownDomainException("error domain not found: " + email.getDomain());
|
throw new UnknownDomainException("error domain not found: " + email.getDomain());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void sendErrorMail(Message msg, String error) {
|
private void sendErrorMail(Message msg, String error) {
|
||||||
logger.info("Trying to send error mail to address " + msg.getFrom());
|
logger.info("Trying to send error mail to address " + msg.getFrom());
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user