@@ -0,0 +1,3557 @@
+package net.f4fs.controller;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map;%0A%0Aimport org.json.simple.parser.ParseException;%0A%0Aimport net.f4fs.bootstrapserver.BootstrapServerAccess;%0Aimport net.f4fs.config.Config;%0Aimport net.f4fs.filesystem.P2PFS;%0Aimport net.f4fs.fspeer.FSPeer;%0Aimport net.f4fs.util.DhtOperationsCommand;%0Aimport net.f4fs.util.IpAddressJsonParser;%0Aimport net.f4fs.util.ShutdownHookThread;%0A%0A%0Apublic class Startup %7B%0A    %0A    private BootstrapServerAccess bootstrapServerAccess;%0A    private FSPeer fsPeer;%0A    private String myIP;%0A    %0A    public Startup()%7B%0A        bootstrapServerAccess = new BootstrapServerAccess();%0A        fsPeer = new FSPeer();%0A        myIP = fsPeer.findLocalIp();%0A    %7D%0A    %0A    public void startWithBootstrapServer()%7B%0A        %0A        List%3CMap%3CString, String%3E%3E ipList = new ArrayList%3C%3E();%0A        try %7B%0A            ipList = IpAddressJsonParser.parse(bootstrapServerAccess.getIpAddressList());%0A        %7D catch (ParseException e) %7B%0A            e.printStackTrace();%0A        %7D%0A        %0A        start(ipList);%0A    %7D%0A    %0A    public void startWithoutBootstrapServer(String connectionIP, String connectionPort)%7B%0A        List%3CMap%3CString, String%3E%3E ipList = new ArrayList%3CMap%3CString, String%3E%3E();%0A        %0A        Map%3CString, String%3E connection = new HashMap%3CString, String%3E();%0A        connection.put(%22address%22, connectionIP); %0A        connection.put(%22port%22, connectionPort); %0A        %0A        ipList.add(connection);%0A        %0A        start(ipList);%0A    %7D%0A    %0A    private void start(List%3CMap%3CString, String%3E%3E ipList)%7B%0A        int nrOfIpAddresses = ipList.size();%0A        bootstrapServerAccess.postIpPortPair(myIP, Config.DEFAULT.getPort());%0A        %0A       // Connect to other peers if any are available, otherwise start as bootstrap peer%0A        try %7B%0A            boolean success = false;%0A%0A            if (nrOfIpAddresses == 0) %7B%0A                fsPeer.startAsBootstrapPeer(myIP, Config.DEFAULT.getPort());%0A                success = true;%0A            %7D else %7B%0A                int counter = 0;%0A%0A                while (!success && (counter %3C nrOfIpAddresses)) %7B%0A                    success = fsPeer.startPeer(myIP,%0A                            Config.DEFAULT.getPort(),%0A                            ipList.get(counter).get(%22address%22),%0A                            Integer.parseInt(ipList.get(counter).get(%22port%22)));%0A                    counter++;%0A                %7D%0A            %7D%0A            %0A            if (!success) %7B%0A                bootstrapServerAccess.removeIpPortPair(myIP, Config.DEFAULT.getPort());%0A                fsPeer.shutdown();%0A                System.out.println(%22%5BShutdown%5D: Bootstrap failed%22);%0A                System.exit(1);%0A            %7D%0A            %0A            // start file system with the connected peer%0A            new P2PFS(fsPeer).mountAndCreateIfNotExists(Config.DEFAULT.getMountPoint());%0A            %0A            // maybe start command line interface%0A            if (Config.DEFAULT.getStartCommandLineInterface()) %7B%0A                DhtOperationsCommand.startCommandLineInterface(fsPeer);   %0A            %7D%0A%0A            // Add shutdown hook so that IP address gets removed from server when%0A            // user does not terminate program correctly on%0A            Runtime.getRuntime().addShutdownHook(new ShutdownHookThread(myIP, Config.DEFAULT.getPort()));%0A%0A            bootstrapServerAccess.removeIpPortPair(myIP, Config.DEFAULT.getPort());%0A            fsPeer.shutdown();%0A        %7D catch (Exception pEx) %7B%0A            pEx.printStackTrace();%0A        %7D%0A    %7D%0A%7D%0A

add startup class