Exemplo n.º 1
0
 private void invitations() {
   int count = 0;
   printer.println("Stored Invitation codes:");
   Collection<Invitation> invitations = core.getInvitaitonManager().allInvitations();
   for (Invitation i : invitations.toArray(new Invitation[invitations.size()])) {
     count++;
     printer.print(i.getCompleteInvitaitonString());
     if (core.getInvitaitonManager()
         .getInvitation(i.getInvitationPassKey())
         .isForwardedInvitation()) {
       printer.println(
           " (Forwarded)  -  Valid next: "
               + Long.toString(
                   (InvitaitonManager.INVITATION_TIMEOUT_FORWARDED
                           - (System.currentTimeMillis() - i.getCreatedAt()))
                       / (1000 * 60))
               + " minutes.");
     } else {
       printer.println(
           " (Manual)  -  Valid next: "
               + Long.toString(
                   (InvitaitonManager.INVITATION_TIMEOUT
                           - (System.currentTimeMillis() - i.getCreatedAt()))
                       / (1000 * 60 * 60))
               + " hours.");
     }
   }
   printer.println("Found " + count + " Invitations.");
 }
Exemplo n.º 2
0
 private void invitationsRemove() {
   int count = 0;
   Collection<Invitation> invitations = core.getInvitaitonManager().allInvitations();
   for (Invitation i : invitations.toArray(new Invitation[invitations.size()])) {
     core.getInvitaitonManager().consume(i.getInvitationPassKey());
     count++;
   }
   printer.println("Removed " + count + " Invitations.");
 }
Exemplo n.º 3
0
 private void clearInvitaitons(String s) throws Exception {
   int i = Integer.parseInt(s);
   if (i >= core.getSettings().getMy().getInvitations()) {
     printer.println("Can't raise number of invitaitons");
     return;
   }
   core.getSettings().getMy().createChecksumAndSetInvitations(i);
   core.saveSettings();
 }
Exemplo n.º 4
0
 public Console(CoreSubsystem core, List<ConsolePlugInExtension> extensions) {
   this.core = core;
   manager = core.getFriendManager();
   if (extensions == null) {
     extensions = new ArrayList<ConsolePlugInExtension>(); // Create empty list
   } else {
     this.extensions = extensions;
   }
 }
Exemplo n.º 5
0
 private void forcesslhandshake() throws IOException {
   for (Friend f : manager.friends()) {
     if (f.getFriendConnection() != null) {
       printer.println("Starting SSL handshake for " + f);
       ((SSLCryptoLayer) core.getCryptoManager().getCryptoLayer())
           .resendHandshake(f.getFriendConnection());
     }
   }
 }
 private void unloadUI() {
   try {
     if (ui == null) {
       if (T.t) {
         T.info("Subsystem already unloaded.");
       }
       return;
     }
     if (tray != null && ti != null) {
       ti.displayMessage(
           "", Language.getLocalizedString(getClass(), "unloading"), TrayIcon.MessageType.NONE);
       balloonClickHandler = null;
     }
     core.restartProgram(false);
   } catch (Exception t) {
     core.reportError(t, this);
   }
 }
 private synchronized void openUI() {
   try {
     if (ui != null) {
       if (T.t) {
         T.info("Subsystem already started.");
       }
       core.uiToFront();
       return;
     }
     Runnable r = (Runnable) Class.forName("org.alliance.launchers.SplashWindow").newInstance();
     SimpleTimer s = new SimpleTimer();
     ui = (Subsystem) Class.forName("org.alliance.ui.UISubsystem").newInstance();
     ui.init(ResourceSingelton.getRl(), core, r);
     if (T.t) {
       T.trace("Subsystem UI started in " + s.getTime());
     }
     r.run();
   } catch (Exception t) {
     core.reportError(t, this);
   }
 }
Exemplo n.º 8
0
  private void share(ArrayList<String> params) throws IOException {
    printer.println("All complete files: ");
    // ArrayList<Hash> al = new
    // ArrayList<Hash>(core.getFileManager().getFileDatabase().getAllHashes());
    // for (Hash h : al) {
    //    FileDescriptor fd = core.getFileManager().getFileDatabase().getFd(h);
    // //    printer.println("  " + fd);
    //   }
    printer.println("");

    printer.println("Incomplete files in cache: ");
    for (Hash h : core.getFileManager().getCache().rootHashes()) {
      BlockFile bf = core.getFileManager().getCache().getBlockFile(h);
      printer.println("  " + bf);
    }
    printer.println("");

    printer.println("Incomplete files in downloads: ");
    for (Hash h : core.getFileManager().getDownloadStorage().rootHashes()) {
      BlockFile bf = core.getFileManager().getDownloadStorage().getBlockFile(h);
      printer.println("  " + bf);
    }
    printer.println("");

    printer.println(
        "Sharing "
            + TextUtils.formatByteSize(core.getShareManager().getFileDatabase().getShareSize())
            + " in "
            + core.getShareManager().getFileDatabase().getNumberOfShares()
            + " files.");
    printer.println("");
  }
Exemplo n.º 9
0
 private void dir(String sharebase, String path) {
   printer.println("Directory listing for " + path + ": ");
   sharebase = TextUtils.makeSurePathIsMultiplatform(sharebase);
   ShareBase b = core.getFileManager().getShareManager().getBaseByPath(sharebase);
   if (b == null) {
     printer.println("Could not find share base for " + sharebase);
     return;
   }
   printer.println("Found share base: " + b);
   /*  for (String s : core.getFileManager().getFileDatabase().getDirectoryListing(b, path)) {
   printer.println(s);
   }*/
 }
  @Override
  public synchronized void shutdown() {
    if (tray != null && ti != null) {
      ti.displayMessage(
          "", Language.getLocalizedString(getClass(), "shutting"), TrayIcon.MessageType.NONE);
      balloonClickHandler = null;
    }

    if (ui != null) {
      ui.shutdown();
      ui = null;
    }
    if (core != null) {
      core.shutdown();
      core = null;
    }
    if (tray != null) {
      tray.remove(ti);
    }
    System.exit(0);
  }
Exemplo n.º 11
0
  public void handleLine(String line) throws Exception {
    String command = line;

    ArrayList<String> params = new ArrayList<String>();
    StringTokenizer st = new StringTokenizer(line);
    if (st.hasMoreTokens()) {
      command = st.nextToken();
      while (st.hasMoreTokens()) {
        params.add(st.nextToken());
      }
    }

    if ("list".equals(command)) {
      list();
    } else if ("test".equals(command)) {
      Thread t =
          new Thread(
              new Runnable() {

                @Override
                public void run() {
                  try {
                    Thread.sleep(1000);
                  } catch (InterruptedException e) {
                    e.printStackTrace(); // To change body of catch statement use File | Settings
                    // | File Templates.
                  }
                  try {
                    core.softRestart();
                  } catch (IOException e) {
                    e.printStackTrace(); // To change body of catch statement use File | Settings
                    // | File Templates.
                  }
                }
              });
      t.start();
    } else if ("connect".equals(command)) {
      connect(params.get(0));
    } else if ("Ping".equals(command)) {
      ping();
    } else if ("startnetlog".equals(command)) {
      startnetlog();
    } else if ("contains".equals(command)) {
      contains(params);
    } else if ("ui".equals(command)) {
      ui();
    } else if ("killui".equals(command)) {
      killUI();
    } else if ("share".equals(command)) {
      share(params);
    } else if ("sharebases".equals(command)) {
      sharebases();
    } else if ("showbuilds".equals(command)) {
      showbuilds();
    } else if ("pingbomb".equals(command)) {
      if (CoreSubsystem.isRunningAsTestSuite()) {
        printer.println("Sending a bunch of pings at random intervals");
        Thread t =
            new Thread(
                new Runnable() {

                  @Override
                  public void run() {
                    for (int i = 0; i < 10000; i++) {
                      Collection<Friend> c = core.getFriendManager().friends();
                      Friend fa[] = new Friend[c.size()];
                      c.toArray(fa);
                      int n = (int) (c.size() * Math.random());
                      final Friend f = fa[n];
                      core.invokeLater(
                          new Runnable() {

                            @Override
                            public void run() {
                              try {
                                f.getFriendConnection().send(new Ping());
                              } catch (IOException e) {
                                e.printStackTrace(); // To change body of catch statement use
                                // File | Settings | File Templates.
                              }
                            }
                          });
                      try {
                        Thread.sleep((long) (Math.random() * 50));
                      } catch (InterruptedException e) {
                      }
                    }
                  }
                });
        t.start();
      } else {
        printer.println("I think not");
      }
    } else if ("gc".equals(command)) {
      gc();
    } else if ("dir".equals(command)) {
      String sharebase = params.get(0);
      params.remove(0);
      String p = "";
      for (String s : params) {
        p += s + " ";
      }
      p = p.trim();
      dir(sharebase, p);
    } else if ("remotedir".equals(command)) {
      int sharebaseIndex = Integer.parseInt(params.get(0));
      String user = params.get(1);
      params.remove(0);
      params.remove(0);

      String p = "";
      for (String s : params) {
        p += s + " ";
      }
      p = p.trim();
      remotedir(sharebaseIndex, user, p);
    } else if ("remotesharebases".equals(command)) {
      remotesharebases(params.get(0));
    } else if ("threads".equals(command)) {
      threads();
    } else if ("filedatabase".equals(command)) {
      filedatabase();
    } else if ("sl".equals(command) || "searchLocal".equals(command)) {
      searchLocal(params);
    } else if ("ci".equals(command)) {
      clearInvitaitons(params.get(0));
    } else if ("Search".equals(command)) {
      search(params);
    } else if ("scan".equals(command)) {
      scan();
    } else if ("bye".equals(command)) {
      bye();
    } else if ("forcesslhandshake".equals(command)) {
      forcesslhandshake();
    } else if ("invitations".equals(command)) {
      invitations();
    } else if ("scaninvi".equals(command)) {
      invitationsScan();
    } else if ("removeinvi".equals(command)) {
      invitationsRemove();
    } else if ("error".equals(command)) {
      throw new Exception("test error");
    } else {
      boolean success = false;
      for (ConsolePlugInExtension ext : extensions) {
        if (ext != null && ext.handleLine(command, printer)) {
          success = true;
          break;
        }
      }
      if (!success) {
        printer.println("Unknown command " + command);
      }
    }
  }
Exemplo n.º 12
0
 private void bye() {
   printer.println("goodbye!");
   core.shutdown();
   System.exit(0);
 }
Exemplo n.º 13
0
 private void scan() {
   core.getShareManager().getShareScanner().startScan(true);
   printer.println("Scanning for new files in share directories (and cache (and downloads))");
 }
Exemplo n.º 14
0
 private void sharebases() {
   printer.println("Sharebases: ");
   for (ShareBase b : core.getFileManager().getShareManager().shareBases()) {
     printer.println("  " + b);
   }
 }
Exemplo n.º 15
0
 private void filedatabase() throws IOException {
   core.getFileManager().getFileDatabase().printStats(printer);
 }
Exemplo n.º 16
0
 private void showbuilds() {
   for (Friend f : core.getFriendManager().friends()) {
     printer.println(
         f.getAllianceBuildNumber() + ": " + core.getFriendManager().nickname(f.getGuid()));
   }
 }
  @Override
  public void init(ResourceLoader rl, Object... params) throws Exception {
    this.rl = rl;
    core = (CoreSubsystem) params[0];
    initTray();
    core.addUICallback(
        new UICallback() {

          @Override
          public void firstDownloadEverFinished() {}

          @Override
          public void callbackRemoved() {}

          public void signalFileDatabaseFlushStarting() {}

          public void signalFileDatabaseFlushComplete() {}

          @Override
          public void nodeOrSubnodesUpdated(Node node) {}

          @Override
          public void noRouteToHost(Node node) {}

          @Override
          public void pluginCommunicationReceived(Friend source, String data) {}

          @Override
          public void searchHits(int srcGuid, int hops, List<SearchHit> hits) {}

          @Override
          public void trace(int level, String message, Exception stackTrace) {}

          @Override
          public void statusMessage(String s) {}

          @Override
          public void statusMessage(String s, boolean b) {}

          @Override
          public void toFront() {}

          @Override
          public void signalFriendAdded(Friend friend) {}

          @Override
          public boolean isUIVisible() {
            return false;
          }

          @Override
          public void logNetworkEvent(String event) {}

          @Override
          public void receivedShareBaseList(Friend friend, String[] shareBaseNames) {}

          @Override
          public void receivedDirectoryListing(
              Friend friend, int i, String s, TreeMap<String, Long> fileSize) {}

          @Override
          public void newUserInteractionQueued(NeedsUserInteraction ui) {
            if (ui instanceof PostMessageInteraction) {
              PostMessageInteraction pmi = (PostMessageInteraction) ui;
              String msg = pmi.getMessage().replaceAll("\\<.*?\\>", ""); // Strip html
              if (pmi instanceof PostMessageToAllInteraction) {
                if (core.getSettings().getInternal().getShowpublicchatmessagesintray() != 0) {
                  ti.displayMessage(
                      Language.getLocalizedString(getClass(), "chatnew"),
                      core.getFriendManager().nickname(pmi.getFromGuid()) + ": " + msg,
                      TrayIcon.MessageType.INFO);
                }
              } else {
                if (core.getSettings().getInternal().getShowprivatechatmessagesintray() != 0) {
                  ti.displayMessage(
                      Language.getLocalizedString(getClass(), "privatenew"),
                      core.getFriendManager().nickname(pmi.getFromGuid()) + ": " + msg,
                      TrayIcon.MessageType.INFO);
                }
              }
            } else {
              if (core.getSettings().getInternal().getShowsystemmessagesintray() != 0) {
                ti.displayMessage(
                    Language.getLocalizedString(getClass(), "attentionheader"),
                    Language.getLocalizedString(getClass(), "attention"),
                    TrayIcon.MessageType.INFO);
              }
            }
            balloonClickHandler =
                new Runnable() {

                  @Override
                  public void run() {
                    openUI();
                  }
                };
          }

          @Override
          public void handleError(final Throwable e, final Object source) {
            ti.displayMessage(
                e.getClass().getName(), e + "\n" + source, TrayIcon.MessageType.ERROR);
            e.printStackTrace();
            balloonClickHandler =
                new Runnable() {

                  @Override
                  public void run() {
                    try {
                      e.printStackTrace();
                      // report error. Use reflection to init dialogs because we want NO references
                      // to UI stuff in this
                      // class - we want this class to load fast (ie load minimal amount of classes)
                      Object errorDialog =
                          Class.forName("org.alliance.ui.dialogs.ErrorDialog").newInstance();
                      Method m =
                          errorDialog.getClass().getMethod("init", Throwable.class, boolean.class);
                      m.invoke(errorDialog, e, false);
                    } catch (Throwable t) {
                      t.printStackTrace();
                    }
                  }
                };
          }
        });
  }
Exemplo n.º 18
0
 private void contains(ArrayList<String> params) {
   printer.println(
       "Result: "
           + core.getShareManager().getFileDatabase().contains(Hash.createFrom(params.get(0))));
 }