Search in sources :

Example 1 with TimeServiceResponder

use of dev.hawala.xns.level4.time.TimeServiceResponder 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)

Example 2 with TimeServiceResponder

use of dev.hawala.xns.level4.time.TimeServiceResponder in project dodo by devhawala.

the class DodoTest method testTimeService.

// time PEX service test (time service)
private static void testTimeService() throws XnsException {
    localSite.pexListen(IDP.KnownSocket.TIME.getSocket(), new TimeServiceResponder(0, 0));
    byte[] requestData = { 0x00, 0x02, 0x00, 0x01 };
    Payload response = localSite.pexRequest(IDP.BROADCAST_ADDR, IDP.KnownSocket.TIME.getSocket(), PEX.ClientType.TIME.getTypeValue(), requestData, 0, requestData.length);
    if (response == null) {
        System.out.println("time response: null (timeout)\n");
    } else if (response instanceof PEX) {
        System.out.println("time response is of type: PEX\n");
        PEX pex = (PEX) response;
        System.out.printf("=> PEX: %s\n", pex.toString());
        System.out.printf("=> PEX.payload: %s\n", pex.payloadToString());
    } else if (response instanceof Error) {
        System.out.println("time response is of type: Error\n");
    } else {
        System.out.printf("time response is of unexpected type: %s\n", response.getClass().getName());
    }
}
Also used : PEX(dev.hawala.xns.level2.PEX) Error(dev.hawala.xns.level2.Error) Payload(dev.hawala.xns.level0.Payload) TimeServiceResponder(dev.hawala.xns.level4.time.TimeServiceResponder)

Example 3 with TimeServiceResponder

use of dev.hawala.xns.level4.time.TimeServiceResponder in project dodo by devhawala.

the class XnsResponder method main.

public static void main(String[] args) throws XnsException {
    // flags/data interpreted from command line args
    boolean verbose = false;
    String hubHost = "localhost";
    int hubPort = 3333;
    long localNetwork = -1;
    long localMachine = -1;
    boolean doTimeSvc = true;
    int localTimeOffsetMinutes = 0;
    int daysBackInTime = 0;
    boolean doRipSvc = true;
    List<NetworkAddress> bfsHostIds = new ArrayList<>();
    // interpret command line args
    for (String arg : args) {
        String a = arg.toLowerCase();
        String value = getValue(a);
        if ("help".equals(a)) {
            usage(true);
        } else if ("+v".equals(a)) {
            verbose = true;
        } else if (a.startsWith("hubHost:")) {
            hubHost = value;
        } else if (a.startsWith("hubPort:")) {
            hubPort = (int) getLong(value, arg, "port");
        } else if (a.startsWith("net:")) {
            localNetwork = getLong(value, arg, "network");
        } else if (a.startsWith("host:")) {
            localMachine = getHost(value, arg);
        } else if ("-time".equals(a)) {
            doTimeSvc = false;
        } else if ("+time".equals(a)) {
            doTimeSvc = true;
            daysBackInTime = 0;
        } else if (a.startsWith("+time:")) {
            doTimeSvc = true;
            localTimeOffsetMinutes = (int) getLong(value, arg, "integer");
        } else if (a.startsWith("daysbackintime")) {
            daysBackInTime = (int) getLong(value, arg, "integer");
        } else if ("-rip".equals(a)) {
            doRipSvc = false;
        } else if ("+rip".equals(a)) {
            doRipSvc = true;
        } else if (a.startsWith("+bfs:")) {
            if (value == null || value.isEmpty()) {
                System.err.printf("** missing value in argument '%s'\n", arg);
                usage();
            }
            String[] parts = value.split("/");
            if (parts.length != 2) {
                System.err.printf("** invalid net/host value '%s' in argument '%s'\n", value, arg);
                usage();
            }
            long bfsNet = getLong(parts[0], arg, "network");
            long bfsHost = getHost(parts[1], arg);
            NetworkAddress addr = NetworkAddress.make();
            addr.network.set((int) bfsNet);
            addr.host.set(bfsHost);
            addr.socket.set(0);
            bfsHostIds.add(addr);
        } else {
            System.err.printf("** invalid argument '%s'\n", arg);
            usage();
        }
    }
    // check configured data / requested features
    if (localNetwork < 0 || localMachine < 0) {
        // no local machine configuration
        System.err.println("** no or invalid local machine configuration given");
        usage();
    }
    if (!doTimeSvc && !doRipSvc && bfsHostIds.isEmpty()) {
        // no responder feature to run
        System.err.println("** no responder feature to activate");
        usage();
    }
    // dump values if requested
    if (verbose) {
        System.out.printf("NetHub ............. : %s:%d\n", hubHost, hubPort);
        System.out.printf("Responder machine .. : net = %d / host-id = 0x%012X\n", localNetwork, localMachine);
        System.out.printf("Time service ....... : %s , GMT offset = %d minutes%s\n", (doTimeSvc) ? "yes" : "no", localTimeOffsetMinutes, (doTimeSvc && daysBackInTime != 0) ? " ( daysBackInTime = " + daysBackInTime + " )" : "");
        System.out.printf("Rip service ........ : %s\n", (doRipSvc) ? "yes" : "no");
        System.out.printf("Bfs responder ...... : %s\n", (!bfsHostIds.isEmpty()) ? "yes" : "no");
        if (!bfsHostIds.isEmpty()) {
            for (NetworkAddress addr : bfsHostIds) {
                System.out.printf("  -> bfs for: net = %d / host-id = 0x%012X\n", addr.network.get(), addr.host.get());
            }
        }
        System.out.println();
    }
    // silence Dodo's logging a bit
    Log.L0.doLog(false);
    Log.L1.doLog(false);
    Log.L2.doLog(false);
    Log.L3.doLog(false);
    Log.L4.doLog(false);
    // configure and start the network engine
    LocalSite.configureHub(hubHost, hubPort);
    LocalSite.configureLocal(localNetwork, localMachine, "XnsResponder", true, false);
    iNetMachine localSite = LocalSite.getInstance();
    // set time base for all time dependent items
    Time2.setTimeWarp(daysBackInTime);
    // time service responder
    if (doTimeSvc) {
        localSite.pexListen(IDP.KnownSocket.TIME.getSocket(), new TimeServiceResponder(localTimeOffsetMinutes, 0));
    }
    // routing protocol responder
    RipResponder ripResponder = null;
    if (doRipSvc) {
        ripResponder = new RipResponder();
        localSite.clientBindToSocket(IDP.KnownSocket.ROUTING.getSocket(), ripResponder);
    }
    // BfS responder for Clearinghouse and Authentication
    if (!bfsHostIds.isEmpty()) {
        // 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(), null, bfsHostIds);
        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(), null, bfsHostIds);
        localSite.pexListen(IDP.KnownSocket.AUTH.getSocket(), new BfsAuthenticationResponder());
    }
}
Also used : ArrayList(java.util.ArrayList) dev.hawala.xns.iNetMachine(dev.hawala.xns.iNetMachine) NetworkAddress(dev.hawala.xns.level4.common.AuthChsCommon.NetworkAddress) BfsClearinghouseResponder(dev.hawala.xns.level4.chs.BfsClearinghouseResponder) RipResponder(dev.hawala.xns.level4.rip.RipResponder) TimeServiceResponder(dev.hawala.xns.level4.time.TimeServiceResponder) BfsAuthenticationResponder(dev.hawala.xns.level4.auth.BfsAuthenticationResponder)

Aggregations

TimeServiceResponder (dev.hawala.xns.level4.time.TimeServiceResponder)3 BfsAuthenticationResponder (dev.hawala.xns.level4.auth.BfsAuthenticationResponder)2 BfsClearinghouseResponder (dev.hawala.xns.level4.chs.BfsClearinghouseResponder)2 RipResponder (dev.hawala.xns.level4.rip.RipResponder)2 dev.hawala.xns.iNetMachine (dev.hawala.xns.iNetMachine)1 Payload (dev.hawala.xns.level0.Payload)1 Error (dev.hawala.xns.level2.Error)1 PEX (dev.hawala.xns.level2.PEX)1 CourierServer (dev.hawala.xns.level3.courier.CourierServer)1 BootResponder (dev.hawala.xns.level4.boot.BootResponder)1 NetworkAddress (dev.hawala.xns.level4.common.AuthChsCommon.NetworkAddress)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 File (java.io.File)1 ArrayList (java.util.ArrayList)1