Skip to content

Commit

Permalink
Tweaked the way init history progress works
Browse files Browse the repository at this point in the history
  • Loading branch information
moloch-- committed Oct 30, 2020
1 parent 96650f0 commit 9152a78
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/burp/BurpExtender.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void main() {
BurpExtender.rootPanel.remove(connectionPanel);

// Select Project Panel
selectProjectPanel.initProjectList();
selectProjectPanel.fetchProjectList();
BurpExtender.rootPanel.add(selectProjectPanel);
BurpExtender.rootPanel.repaint();
BurpExtender.rootPanel.revalidate();
Expand Down
26 changes: 17 additions & 9 deletions src/burp/Multiplayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class Multiplayer implements IHttpListener, OnEditCallback {

private Integer dbCount;
private Integer dbLoaded;
private final List<OnLoadEventCallback> onLoadEventCallbacks = new ArrayList<>();
private final List<OnLoadCallback> onLoadEventCallbacks = new ArrayList<>();

private final IBurpExtenderCallbacks callbacks;
private final BurpExtender extension;
Expand Down Expand Up @@ -175,19 +175,27 @@ private void initalizeHistory() {
Result<Integer> countCursor = http().count().run(dbConnect(), Integer.class);
dbCount = countCursor.single();
logger.debug("Expect %d results ...", dbCount);
dbLoaded = 0;

dbLoaded = 0; // We need to initialize this before any OnLoad event

if (dbCount < 1) {
triggerOnLoadEvent();
return;
}

// This can be increased to reduce the number of queries used to
// load the history, but in my testing it doesn't seem to have a
// major impact on load times so I left it at 1 for now.
int step = 1;

while (dbLoaded < dbCount) {
Result<MultiplayerRequestResponse> result = http().skip(dbLoaded).limit(1).run(dbConn, MultiplayerRequestResponse.class);
MultiplayerRequestResponse entry = result.single();
logger.debug("Got entry %d of %d: %s", dbLoaded, dbCount, entry);
history.add(entry);
dbLoaded++;
Result<MultiplayerRequestResponse> result = http().skip(dbLoaded).limit(step).run(dbConn, MultiplayerRequestResponse.class);
while (result.hasNext()) {
MultiplayerRequestResponse entry = result.next();
logger.debug("Got entry %d of %d: %s", dbLoaded, dbCount, entry);
history.add(entry);
}
dbLoaded += step;
triggerOnLoadEvent();
}
logger.debug("Results done.");
Expand Down Expand Up @@ -481,11 +489,11 @@ private Connection dbConnect() {
return r.connection().hostname(dbHostname).port(dbPort).connect();
}

public void registerOnLoadEventCallback(OnLoadEventCallback callback) {
public void registerOnLoadEventCallback(OnLoadCallback callback) {
onLoadEventCallbacks.add(callback);
}

public void unregisterOnLoadEventCallback(OnLoadEventCallback callback) {
public void unregisterOnLoadEventCallback(OnLoadCallback callback) {
onLoadEventCallbacks.remove(callback);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* @author moloch
*/
public interface OnLoadEventCallback {
public interface OnLoadCallback {

public void onLoad(Integer loaded, Integer count);

Expand Down
15 changes: 8 additions & 7 deletions src/burp/gui/LoadingPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
import burp.IBurpExtenderCallbacks;
import burp.Multiplayer;
import burp.MultiplayerLogger;
import burp.OnLoadEventCallback;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import burp.OnLoadCallback;

/**
*
* @author moloch
*/
public class LoadingPanel extends javax.swing.JPanel implements OnLoadEventCallback {
public class LoadingPanel extends javax.swing.JPanel implements OnLoadCallback {

private final Multiplayer multiplayer;
private final List<Runnable> onCompleteCallbacks = new ArrayList<>();
Expand All @@ -39,26 +39,27 @@ public LoadingPanel(Multiplayer multiplayer, MultiplayerLogger logger) {
public void initialize() {
multiplayer.registerOnLoadEventCallback(this);
multiplayer.initializeHistory();
multiplayer.startChangefeed();
}

@Override
public void onLoad(Integer loaded, Integer count) {
logger.debug("Loaded event: %d of %d", loaded, count);

if (loaded == null || count == null || count <= loaded) {
logger.debug("History initialization completed");
onComplete();
}

if (0 < count) {
float progress = (float) loaded / (float) count;
loadingProgressBar.setValue((int) Math.round(progress * 100.0));
}

if (Objects.equals(loaded, count)) {
logger.debug("History initialization completed");
onComplete();
}
}

private void onComplete() {
multiplayer.unregisterOnLoadEventCallback(this);
multiplayer.startChangefeed();
triggerOnCompleteCallbacks();
}

Expand Down
1 change: 1 addition & 0 deletions src/burp/gui/SelectProjectPanel.form
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<Property name="model" type="javax.swing.ListModel" editor="org.netbeans.modules.form.editors2.ListModelEditor">
<StringArray count="0"/>
</Property>
<Property name="selectionMode" type="int" value="0"/>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_InitCodePre" type="java.lang.String" value="projectsJList.setModel(projectListModel);"/>
Expand Down
5 changes: 3 additions & 2 deletions src/burp/gui/SelectProjectPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public SelectProjectPanel(Multiplayer multiplayer, MultiplayerLogger logger) {
initComponents();
}

public void initProjectList() {
public void fetchProjectList() {
logger.debug("Fetching project list ...");
projectListModel.clear();
List<String> projects = multiplayer.getProjects();
Expand Down Expand Up @@ -78,6 +78,7 @@ private void initComponents() {
deleteProjectButton = new javax.swing.JButton();

projectsJList.setModel(projectListModel);
projectsJList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
jScrollPane1.setViewportView(projectsJList);

createProjectButton.setText("Create Project");
Expand Down Expand Up @@ -154,7 +155,7 @@ private void deleteProjectButtonActionPerformed(java.awt.event.ActionEvent evt)
if (confirmation == 0) {
multiplayer.deleteProject(project);
projectsJList.clearSelection();
initProjectList();
fetchProjectList();
}
}
}//GEN-LAST:event_deleteProjectButtonActionPerformed
Expand Down

0 comments on commit 9152a78

Please sign in to comment.