Search in sources :

Example 1 with CourierServer

use of dev.hawala.xns.level3.courier.CourierServer in project dodo by devhawala.

the class DodoServer method main.

public static void main(String[] args) throws XnsException {
    String machinesFile = null;
    String baseCfgFile = null;
    String cfgFile = null;
    boolean dumpChs = false;
    // get commandline args
    for (String arg : args) {
        if (arg.toLowerCase().startsWith("-machinecfg:")) {
            String[] parts = arg.split(":");
            machinesFile = parts[1];
        } else if (arg.toLowerCase().startsWith("-basecfg:")) {
            String[] parts = arg.split(":");
            baseCfgFile = parts[1];
        } else if ("-dumpchs".equalsIgnoreCase(arg)) {
            dumpChs = true;
        } else if (cfgFile == null) {
            cfgFile = arg;
        } else {
            System.out.printf("Warning: ignoring unknown argument: %s\n", arg);
        }
    }
    // load machines configuration
    if (!MachineIds.loadDefinitions(machinesFile)) {
        System.out.println("!! failed to load machines configuration");
    }
    // load configuration(s)
    if (baseCfgFile == null) {
        File f = new File(DEFAULT_BASECONFIG_FILE);
        if (f.exists() && f.canRead()) {
            baseCfgFile = DEFAULT_BASECONFIG_FILE;
            System.out.printf("Found and using default commons configuration: %s\n", baseCfgFile);
        }
    }
    if (cfgFile == null && (new File(DEFAULT_CONFIG_FILE)).canRead()) {
        cfgFile = DEFAULT_CONFIG_FILE;
    }
    if (baseCfgFile != null) {
        initializeConfiguration(baseCfgFile);
    }
    if (cfgFile != null && !initializeConfiguration(cfgFile)) {
        return;
    }
    // put parts of the configuration data as defaults for client machines
    MachineIds.setDefault(MachineIds.CFG_AUTH_SKIP_TIMESTAMP_CHECKS, authSkipTimestampChecks);
    MachineIds.setDefault(MachineIds.CFG_BOOTSVC_SIMPLEDATA_SEND_INTERVAL, bootServiceSimpleDataSendInterval);
    MachineIds.setDefault(MachineIds.CFG_BOOTSVC_SPPDATA_SEND_INTERVAL, bootServiceSppDataSendInterval);
    MachineIds.setDefault(MachineIds.CFG_SPP_HANDSHAKE_SENDACK_COUNTDOWN, sppHandshakeSendackCountdown);
    MachineIds.setDefault(MachineIds.CFG_SPP_RESEND_DELAY, sppResendDelay);
    MachineIds.setDefault(MachineIds.CFG_SPP_HANDSHAKE_RESEND_COUNTDOWN, sppHandshakeResendCountdown);
    MachineIds.setDefault(MachineIds.CFG_SPP_HANDSHAKE_MAX_RESENDS, sppHandshakeMaxResends);
    MachineIds.setDefault(MachineIds.CFG_SPP_RESEND_PACKET_COUNT, sppResendPacketCount);
    MachineIds.setDefault(MachineIds.CFG_SPP_SENDING_TIME_GAP, sppSendingTimeGap);
    // this parameter is global to all SPP connections (cannot be specified at client machine level)
    SppConnection.setHandshakeCheckInterval(sppHandshakeCheckInterval);
    // open CHS database if there are services requiring it
    ChsDatabase chsDatabase = null;
    if (startChsAndAuth || !fileServiceSpecs.isEmpty()) {
        // create the clearinghouse database
        chsDatabase = new ChsDatabase(networkNo, organizationName, domainName, chsDatabaseRoot, allowBlanksInObjectNames);
        if (dumpChs) {
            System.out.println("\n==\n== machine-id pre-definitions:\n==\n");
            MachineIds.dump();
            System.out.println("\n==\n== clearinghouse database dump: \n==\n");
            chsDatabase.dump();
            System.out.println("\n==\n== end of machine-id and clearinghouse database dumps\n==\n");
        }
    }
    // check if we have undefined machine names, aborting startup if any
    List<String> undefinedMachineNames = MachineIds.getUndefinedMachineNames();
    if (!undefinedMachineNames.isEmpty()) {
        System.out.println("The following machine names or IDs are undefined or invalid:");
        for (String name : undefinedMachineNames) {
            System.out.printf(" -> name: %s\n", name);
        }
        System.out.printf("Aborting Dodo startup ...\n... please correct the configuration or define the above names in the machine ids file (%s)\n", machinesFile);
        System.exit(2);
    }
    // configure and start the network engine
    LocalSite.configureHub(netHubHost, netHubPort);
    LocalSite.configureLocal(networkNo, machineId, "DodoServer", doChecksums, doDarkstarWorkaround);
    localSite = LocalSite.getInstance();
    // set time base for all time dependent items
    Time2.setTimeWarp(daysBackInTime);
    // boot service
    if (startBootService) {
        BootResponder bootService = new BootResponder(bootServiceBasedir, bootServiceVerbose);
        localSite.clientBindToSocket(IDP.KnownSocket.BOOT.getSocket(), bootService);
    }
    // echo service
    if (startEchoService) {
        localSite.clientBindToSocket(IDP.KnownSocket.ECHO.getSocket(), new EchoResponder());
    }
    // time service
    if (startTimeService) {
        localSite.pexListen(IDP.KnownSocket.TIME.getSocket(), new TimeServiceResponder(localTimeOffsetMinutes, timeServiceSendingTimeGap));
    }
    // routing protocol responder
    RipResponder ripResponder = null;
    if (startRipService) {
        ripResponder = new RipResponder();
        localSite.clientBindToSocket(IDP.KnownSocket.ROUTING.getSocket(), ripResponder);
    }
    // clearinghouse and authentication services
    if (startChsAndAuth) {
        // broadcast for clearinghouse service
        // one common implementation for versions 2 and 3, as both versions have the same RetrieveAddresses method
        Clearinghouse3Impl.init(localSite.getNetworkId(), localSite.getMachineId(), chsDatabase);
        localSite.pexListen(IDP.KnownSocket.CLEARINGHOUSE.getSocket(), new BfsClearinghouseResponder(ripResponder), null);
        // broadcast for authentication service
        // one common implementation for versions 1, 2 and 3, as all versions are assumed to have
        // the same (undocumented) RetrieveAddresses method
        Authentication2Impl.init(localSite.getNetworkId(), localSite.getMachineId(), chsDatabase);
        localSite.pexListen(IDP.KnownSocket.AUTH.getSocket(), new BfsAuthenticationResponder());
        // register clearinghouse and authentication courier programs in registry
        Clearinghouse3Impl.register();
        Authentication2Impl.register();
        // start the mailService always co-located with the clearinghouse
        if (mailServiceVolumePath != null) {
            MailingOldImpl.init(localSite.getNetworkId(), localSite.getMachineId(), chsDatabase, mailServiceVolumePath);
            MailingOldImpl.register();
            MailingNewImpl.init(localSite.getNetworkId(), localSite.getMachineId(), chsDatabase, MailingOldImpl.getMailService());
            MailingNewImpl.register();
            localSite.pexListen(0x001A, new MailingExpeditedCourierResponder());
        }
    }
    // print service
    if (printServiceName != null && printServiceOutputDirectory != null) {
        try {
            Printing3Impl.init(printServiceName, printServiceOutputDirectory, printServiceDisassembleIp, printServicePaperSizes, printServiceIp2PsProcFilename, printServicePsPostprocessor);
            Printing3Impl.register();
        } catch (Exception e) {
            System.out.printf("Error starting printservice '%s': %s\n", printServiceName, e.getMessage());
        }
    }
    // file service(s)
    if (fileServiceSpecs.size() > 0) {
        // initialize
        FilingImpl.init(localSite.getNetworkId(), localSite.getMachineId(), chsDatabase);
        // open volume(s)
        int openVolumes = 0;
        for (Entry<String, String> spec : fileServiceSpecs.entrySet()) {
            ThreePartName serviceName = ThreePartName.make().from(spec.getKey());
            String volumeBasedirName = spec.getValue();
            if (FilingImpl.addVolume(serviceName, volumeBasedirName)) {
                openVolumes++;
            }
        }
        // register Courier implementation if volume(s) were successfully opened
        if (openVolumes > 0) {
            FilingImpl.register();
        } else {
            System.out.printf("No volumes opened successfully, not registering Filing to Courier");
        }
    }
    // run courier server with dispatcher
    CourierServer courierServer = new CourierServer(localSite);
    // silence logging a bit
    Log.L0.doLog(false);
    Log.L1.doLog(false);
    Log.L2.doLog(false);
    Log.L3.doLog(false);
    Log.L4.doLog(false);
/*
		 * let the server machine run...
		 */
}
Also used : BootResponder(dev.hawala.xns.level4.boot.BootResponder) CourierServer(dev.hawala.xns.level3.courier.CourierServer) MailingExpeditedCourierResponder(dev.hawala.xns.level4.mailing.MailingExpeditedCourierResponder) BfsClearinghouseResponder(dev.hawala.xns.level4.chs.BfsClearinghouseResponder) ThreePartName(dev.hawala.xns.level4.common.AuthChsCommon.ThreePartName) RipResponder(dev.hawala.xns.level4.rip.RipResponder) ChsDatabase(dev.hawala.xns.level4.common.ChsDatabase) EchoResponder(dev.hawala.xns.level4.echo.EchoResponder) File(java.io.File) TimeServiceResponder(dev.hawala.xns.level4.time.TimeServiceResponder) BfsAuthenticationResponder(dev.hawala.xns.level4.auth.BfsAuthenticationResponder)

Aggregations

CourierServer (dev.hawala.xns.level3.courier.CourierServer)1 BfsAuthenticationResponder (dev.hawala.xns.level4.auth.BfsAuthenticationResponder)1 BootResponder (dev.hawala.xns.level4.boot.BootResponder)1 BfsClearinghouseResponder (dev.hawala.xns.level4.chs.BfsClearinghouseResponder)1 ThreePartName (dev.hawala.xns.level4.common.AuthChsCommon.ThreePartName)1 ChsDatabase (dev.hawala.xns.level4.common.ChsDatabase)1 EchoResponder (dev.hawala.xns.level4.echo.EchoResponder)1 MailingExpeditedCourierResponder (dev.hawala.xns.level4.mailing.MailingExpeditedCourierResponder)1 RipResponder (dev.hawala.xns.level4.rip.RipResponder)1 TimeServiceResponder (dev.hawala.xns.level4.time.TimeServiceResponder)1 File (java.io.File)1