Home > Articles > Networking > Network Design & Architecture

  • Print
  • + Share This

7.7 Adding the PPP Daemon to DataLogger

Now that we have an implementation of a PPP daemon and the supporting data link classes, we can enhance the DataLogger class to accept network connections over both PPP and Ethernet interfaces.

Listing 7.22 shows the additions and modifications made to the DataLogger class for the purpose of adding PPP daemon support. The first change to notice is that DataLogger creates and starts a new instance of PPPDaemon on construction. The other change to DataLogger is that it now implements the PPPDaemonListener (Listing 7.11) interface and therefore provides implementations for the daemonError and isValidUser methods. The daemonError method is invoked when a persistent error is preventing PPPDaemon from establishing PPP connections. As implemented below, daemonError stops the PPP server. However, DataLogger continues to run, allowing connections over the Ethernet network interface only.

Listing 7.22 DataLogger changes

class DataLogger extends Thread implements PPPDaemonListener {
  ...
  PPPDaemon pppd;
  private String name; 
  private String password; 

  DataLogger(int samples, int delay, String name, String password) 
    throws PPPException, LoggingException {

    // Set authentication information
    this.name = name;
    this.password = password;
    ...
    // Create a server to manage PPP dial-up requests
    PPPDaemon pppd = new PPPDaemon(this, "serial0", 19200);
    pppd.startDaemon();
  }

  public void daemonError(String error) {
    System.err.println("Error in PPP server:"+error);
    pppd.stopDaemon();
  }

  public boolean isValidUser(String name, String password) {
    return (this.name.equals(name) && 
        this.password.equals(password));
  }

  ...

  public static void main(String[] args) {
    System.out.println("Starting DataLogger ...");
    if (args.length != 4) {
      System.out.println(
        "Usage: java DataLogger samples delay username password");
      System.exit(1);
    }
    ...
    try {
      (new DataLogger(samples, delay, args[2], args[3])).start();
    } catch (Exception e) {
      ...
    }
  }
}

Since DataLogger is now responsible for validating login requests, we'll add instance fields to store a user name and password. Rather than choose arbitrary hard-coded strings to use for validation of login information, we'll modify the main method to require the user name and password on the command line. We'll also modify the constructor as well to accept login information and store it in the name and password private instance fields. These strings will be used as a direct comparison to the login information passed to the isValidUser method. Note that the login scheme that we're supporting in this example with our simple user name and password match is PAP (Password Authentication Protocol). PAP was chosen because it is the most straightforward to implement. The main goal of this example is to focus on the mechanics of writing multihomed network servers rather than getting bogged down with security details.

  • + Share This
  • 🔖 Save To Your Account

Related Resources

There are currently no related titles. Please check back later.