Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature enabling log file upload to mediators #5953

Merged
merged 4 commits into from Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/src/main/java/bisq/common/file/FileUtil.java
Expand Up @@ -130,7 +130,7 @@ public static void deleteDirectory(File file,
try {
deleteFileIfExists(file, ignoreLockedFiles);
} catch (Throwable t) {
log.error("Could not delete file. Error=" + t.toString());
log.error("Could not delete file. Error=" + t);
throw new IOException(t);
}
}
Expand Down
17 changes: 8 additions & 9 deletions core/src/main/java/bisq/core/support/dispute/DisputeManager.java
Expand Up @@ -145,7 +145,7 @@ public void requestPersistence() {
@Override
public NodeAddress getPeerNodeAddress(ChatMessage message) {
Optional<Dispute> disputeOptional = findDispute(message);
if (!disputeOptional.isPresent()) {
if (disputeOptional.isEmpty()) {
log.warn("Could not find dispute for tradeId = {} traderId = {}",
message.getTradeId(), message.getTraderId());
return null;
Expand All @@ -156,7 +156,7 @@ public NodeAddress getPeerNodeAddress(ChatMessage message) {
@Override
public PubKeyRing getPeerPubKeyRing(ChatMessage message) {
Optional<Dispute> disputeOptional = findDispute(message);
if (!disputeOptional.isPresent()) {
if (disputeOptional.isEmpty()) {
log.warn("Could not find dispute for tradeId = {} traderId = {}",
message.getTradeId(), message.getTraderId());
return null;
Expand Down Expand Up @@ -325,7 +325,7 @@ protected void onOpenNewDisputeMessage(OpenNewDisputeMessage openNewDisputeMessa
if (isAgent(dispute)) {
if (!disputeList.contains(dispute)) {
Optional<Dispute> storedDisputeOptional = findDispute(dispute);
if (!storedDisputeOptional.isPresent()) {
if (storedDisputeOptional.isEmpty()) {
disputeList.add(dispute);
sendPeerOpenedDisputeMessage(dispute, contract, peersPubKeyRing);
} else {
Expand Down Expand Up @@ -378,7 +378,7 @@ protected void onPeerOpenedDisputeMessage(PeerOpenedDisputeMessage peerOpenedDis
Dispute dispute = peerOpenedDisputeMessage.getDispute();

Optional<Trade> optionalTrade = tradeManager.getTradeById(dispute.getTradeId());
if (!optionalTrade.isPresent()) {
if (optionalTrade.isEmpty()) {
return;
}

Expand All @@ -399,11 +399,10 @@ protected void onPeerOpenedDisputeMessage(PeerOpenedDisputeMessage peerOpenedDis
if (!isAgent(dispute)) {
if (!disputeList.contains(dispute)) {
Optional<Dispute> storedDisputeOptional = findDispute(dispute);
if (!storedDisputeOptional.isPresent()) {
if (storedDisputeOptional.isEmpty()) {
disputeList.add(dispute);
trade.setDisputeState(getDisputeStateStartedByPeer());
tradeManager.requestPersistence();
errorMessage = null;
} else {
// valid case if both have opened a dispute and agent was not online.
log.debug("We got a dispute already open for that trade and trading peer. TradeId = {}",
Expand Down Expand Up @@ -452,7 +451,7 @@ public void sendOpenNewDisputeMessage(Dispute dispute,
}

Optional<Dispute> storedDisputeOptional = findDispute(dispute);
if (!storedDisputeOptional.isPresent() || reOpen) {
if (storedDisputeOptional.isEmpty() || reOpen) {
String disputeInfo = getDisputeInfo(dispute);
String disputeMessage = getDisputeIntroForDisputeCreator(disputeInfo);
String sysMsg = dispute.isSupportTicket() ?
Expand Down Expand Up @@ -836,7 +835,7 @@ public Optional<Dispute> findDispute(String tradeId) {

public Optional<Trade> findTrade(Dispute dispute) {
Optional<Trade> retVal = tradeManager.getTradeById(dispute.getTradeId());
if (!retVal.isPresent()) {
if (retVal.isEmpty()) {
retVal = closedTradableManager.getClosedTrades().stream().filter(e -> e.getId().equals(dispute.getTradeId())).findFirst();
}
return retVal;
Expand Down Expand Up @@ -972,7 +971,7 @@ private Price getPrice(String currencyCode) {
long roundedToLong = MathUtils.roundDoubleToLong(scaled);
return Price.valueOf(currencyCode, roundedToLong);
} catch (Exception e) {
log.error("Exception at getPrice / parseToFiat: " + e.toString());
log.error("Exception at getPrice / parseToFiat: " + e);
return null;
}
} else {
Expand Down
@@ -1,3 +1,20 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.core.support.dispute.mediation;

import bisq.network.p2p.AckMessage;
Expand Down Expand Up @@ -27,7 +44,7 @@ public class FileTransferReceiver extends FileTransferSession {
protected final String zipFilePath;

public FileTransferReceiver(NetworkNode networkNode, NodeAddress peerNodeAddress,
String tradeId, int traderId, String traderRole, @Nullable FileTransferSession.FtpCallback callback) throws IOException {
String tradeId, int traderId, String traderRole, @Nullable FileTransferSession.FtpCallback callback) throws IOException {
super(networkNode, peerNodeAddress, tradeId, traderId, traderRole, callback);
zipFilePath = ensureReceivingDirectoryExists().getAbsolutePath() + FileSystems.getDefault().getSeparator() + zipId + ".zip";
}
Expand Down Expand Up @@ -55,9 +72,7 @@ public void initReceiveSession(String uid, long expectedFileBytes) {
initSessionTimer();
log.info("Received a start file transfer request, tradeId={}, traderId={}, size={}", fullTradeId, traderId, expectedFileBytes);
log.info("New file will be written to {}", zipFilePath);
UserThread.execute(() -> {
ackReceivedPart(uid, networkNode, peerNodeAddress);
});
UserThread.execute(() -> ackReceivedPart(uid, networkNode, peerNodeAddress));
}

private void processReceivedBlock(FileTransferPart ftp, NetworkNode networkNode, NodeAddress peerNodeAddress) {
Expand Down
@@ -1,3 +1,20 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.core.support.dispute.mediation;

import bisq.network.p2p.FileTransferPart;
Expand Down Expand Up @@ -39,7 +56,7 @@ public class FileTransferSender extends FileTransferSession {
protected final String zipFilePath;

public FileTransferSender(NetworkNode networkNode, NodeAddress peerNodeAddress,
String tradeId, int traderId, String traderRole, @Nullable FileTransferSession.FtpCallback callback) {
String tradeId, int traderId, String traderRole, @Nullable FileTransferSession.FtpCallback callback) {
super(networkNode, peerNodeAddress, tradeId, traderId, traderRole, callback);
zipFilePath = Config.appDataDir() + FileSystems.getDefault().getSeparator() + zipId + ".zip";
updateProgress();
Expand All @@ -54,10 +71,10 @@ public void createZipFileToSend() {
Stream<Path> paths = Files.walk(Paths.get(Config.appDataDir().toString()), 1);
paths.filter(Files::isRegularFile).forEach(externalTxtFile -> {
try {
// always include bisq.log; and other .log files if they contain the TradeId
if (externalTxtFile.getFileName().toString().equals("bisq.log") ||
(externalTxtFile.getFileName().toString().matches(".*.log") &&
doesFileContainKeyword(externalTxtFile.toFile(), fullTradeId))) {
// always include bisq.log; and other .log files if they contain the TradeId
if (externalTxtFile.getFileName().toString().equals("bisq.log") ||
(externalTxtFile.getFileName().toString().matches(".*.log") &&
doesFileContainKeyword(externalTxtFile.toFile(), fullTradeId))) {
Path pathInZipfile = zipfs.getPath(zipId + "/" + externalTxtFile.getFileName().toString());
log.info("adding {} to zip file {}", pathInZipfile, zipfs);
Files.copy(externalTxtFile, pathInZipfile, StandardCopyOption.REPLACE_EXISTING);
Expand Down Expand Up @@ -117,7 +134,7 @@ public void retrySend() {
}

protected void uploadData() {
if (!dataAwaitingAck.isPresent()) {
if (dataAwaitingAck.isEmpty()) {
return;
}
FileTransferPart ftp = dataAwaitingAck.get();
Expand All @@ -127,7 +144,7 @@ protected void uploadData() {
}

public boolean processAckForFilePart(String ackUid) {
if (!dataAwaitingAck.isPresent()) {
if (dataAwaitingAck.isEmpty()) {
log.warn("We received an ACK we were not expecting. {}", ackUid);
return false;
}
Expand Down
@@ -1,3 +1,20 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.core.support.dispute.mediation;

import bisq.network.p2p.AckMessage;
Expand All @@ -23,8 +40,8 @@
import java.util.Optional;
import java.util.concurrent.TimeUnit;

import lombok.extern.slf4j.Slf4j;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import org.jetbrains.annotations.NotNull;

Expand All @@ -39,7 +56,9 @@ public abstract class FileTransferSession implements MessageListener {

public interface FtpCallback {
void onFtpProgress(double progressPct);

void onFtpComplete(FileTransferSession session);

void onFtpTimeout(String statusMsg, FileTransferSession session);
}

Expand Down
Expand Up @@ -141,19 +141,17 @@ protected AckMessageSourceType getAckMessageSourceType() {

@Override
public void cleanupDisputes() {
disputeListService.cleanupDisputes(tradeId -> {
tradeManager.getTradeById(tradeId).filter(trade -> trade.getPayoutTx() != null)
.ifPresent(trade -> {
tradeManager.closeDisputedTrade(tradeId, Trade.DisputeState.MEDIATION_CLOSED);
});
});
disputeListService.cleanupDisputes(tradeId -> tradeManager.getTradeById(tradeId).filter(trade -> trade.getPayoutTx() != null)
.ifPresent(trade -> tradeManager.closeDisputedTrade(tradeId, Trade.DisputeState.MEDIATION_CLOSED)));
}

@Override
protected String getDisputeInfo(Dispute dispute) {
String role = Res.get("shared.mediator").toLowerCase();
NodeAddress agentNodeAddress = getAgentNodeAddress(dispute);
checkNotNull(agentNodeAddress, "Agent node address must not be null");
String roleContextMsg = Res.get("support.initialMediatorMsg",
DisputeAgentLookupMap.getKeybaseLinkForAgent(getAgentNodeAddress(dispute).getFullAddress()));
DisputeAgentLookupMap.getKeybaseLinkForAgent(agentNodeAddress.getFullAddress()));
String link = "https://bisq.wiki/Dispute_resolution#Level_2:_Mediation";
return Res.get("support.initialInfo", role, roleContextMsg, role, link);
}
Expand Down Expand Up @@ -181,7 +179,7 @@ public void onDisputeResultMessage(DisputeResultMessage disputeResultMessage) {
checkNotNull(chatMessage, "chatMessage must not be null");
Optional<Dispute> disputeOptional = findDispute(disputeResult);
String uid = disputeResultMessage.getUid();
if (!disputeOptional.isPresent()) {
if (disputeOptional.isEmpty()) {
log.warn("We got a dispute result msg but we don't have a matching dispute. " +
"That might happen when we get the disputeResultMessage before the dispute was created. " +
"We try again after 2 sec. to apply the disputeResultMessage. TradeId = " + tradeId);
Expand Down Expand Up @@ -293,7 +291,7 @@ private void processFilePartReceived(FileTransferPart ftp) {
}
// we create a new session which is related to an open dispute from our list
Optional<Dispute> dispute = findDispute(ftp.getTradeId(), ftp.getTraderId());
if (!dispute.isPresent()) {
if (dispute.isEmpty()) {
log.error("Received log upload request for unknown TradeId/TraderId {}/{}", ftp.getTradeId(), ftp.getTraderId());
return;
}
Expand Down
14 changes: 7 additions & 7 deletions core/src/main/resources/i18n/displayStrings.properties
Expand Up @@ -1233,26 +1233,26 @@ support.state=State
support.chat=Chat
support.closed=Closed
support.open=Open
support.sendLogFiles=Send Log Files
support.process=Process
support.buyerOfferer=BTC buyer/Maker
support.sellerOfferer=BTC seller/Maker
support.buyerTaker=BTC buyer/Taker
support.sellerTaker=BTC seller/Taker
support.sendLogs.title=Send Logs
support.sendLogs.backgroundInfo=When traders experience a bug, mediators and support staff will often request copies of the users logs to diagnose the issue.\n\n\
Upon pressing [Send], your log file will be compressed and transmitted direct to the mediator.
support.sendLogs.step1=Create Zip Archive of Logs
support.sendLogs.title=Send Log Files
support.sendLogs.backgroundInfo=When you experience a bug, mediators and support staff will often request copies of the your log files to diagnose the issue.\n\n\ \
Upon pressing 'Send', your log files will be compressed and transmitted directly to the mediator.
support.sendLogs.step1=Create Zip Archive of Log Files
support.sendLogs.step2=Connection Request to Mediator
support.sendLogs.step3=Upload Archived Log Data
support.sendLogs.waiting=Waiting for your input
support.sendLogs.send=Send
support.sendLogs.stop=Stop
support.sendLogs.cancel=Cancel
support.sendLogs.init=Initializing
support.sendLogs.retry=Retrying send
support.sendLogs.stopped=Transfer stopped
support.sendLogs.progress=Transfer progress: %.0f%%
support.sendLogs.finished=Transfer complete!
support.sendLogs.command=Press [Send] to retry, or [Stop] to abort
support.sendLogs.command=Press 'Send' to retry, or 'Stop' to abort

support.backgroundInfo=Bisq is not a company, so it handles disputes differently.\n\n\
Traders can communicate within the application via secure chat on the open trades screen to try solving disputes on their own. \
Expand Down
@@ -1,3 +1,20 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.core.support.dispute.mediation;

import bisq.network.p2p.FileTransferPart;
Expand All @@ -14,7 +31,8 @@
import org.junit.Before;
import org.junit.Test;

import static org.mockito.Mockito.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class FileTransferSessionTest implements FileTransferSession.FtpCallback {

Expand Down
2 changes: 1 addition & 1 deletion desktop/src/main/java/bisq/desktop/bisq.css
Expand Up @@ -2032,7 +2032,7 @@ textfield */
}

.dispute-chat-border {
-fx-background-color: -bs-color-blue-5;
-fx-background-color: -bs-support-chat-background;
}

/********************************************************************************************************************
Expand Down