-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updating file name, property path and known peer service to be includ…
…ed into peerExplorer Updating known peers origin, adding tests and small fixes Removing unnecesary log to avoid log injection Load active peers from previous session saved into file.
- Loading branch information
Showing
16 changed files
with
413 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
rskj-core/src/main/java/co/rsk/net/discovery/KnownPeersSaver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* This file is part of RskJ | ||
* Copyright (C) 2024 RSK Labs Ltd. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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 Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package co.rsk.net.discovery; | ||
|
||
import org.ethereum.util.SimpleFileWriter; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
|
||
public class KnownPeersSaver { | ||
private static final Logger logger = LoggerFactory.getLogger(KnownPeersSaver.class); | ||
private final Path peerListFileDir; | ||
private final SimpleFileWriter fileDataSaver; | ||
|
||
public KnownPeersSaver(Path peerListFileDir) { | ||
this(peerListFileDir, SimpleFileWriter.getInstance()); | ||
} | ||
|
||
public KnownPeersSaver(Path peerListFileDir, SimpleFileWriter fileDataSaver) { | ||
this.peerListFileDir = peerListFileDir; | ||
this.fileDataSaver = fileDataSaver; | ||
} | ||
|
||
public void savePeers(List<String> knownPeers) { | ||
logger.debug("Stop in progress.. Saving known peers list to file"); | ||
if (knownPeers != null && !knownPeers.isEmpty()) { | ||
|
||
StringBuilder sb = new StringBuilder(); | ||
for (String peerAddress : knownPeers) { | ||
logger.debug("Saving knew peer: {}", peerAddress); | ||
sb.append(peerAddress).append("\n"); | ||
} | ||
try { | ||
fileDataSaver.saveDataIntoFile(sb.toString(), peerListFileDir); | ||
} catch (IOException e) { | ||
logger.error("Error saving active peers to file: {}", e.getMessage()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
rskj-core/src/main/java/org/ethereum/util/SimpleFileWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* This file is part of RskJ | ||
* Copyright (C) 2023 RSK Labs Ltd. | ||
* (derived from ethereumJ library, Copyright (c) 2016 <ether.camp>) | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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 Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.ethereum.util; | ||
|
||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; | ||
|
||
public class SimpleFileWriter { | ||
private static final String TMP = ".tmp"; | ||
private static SimpleFileWriter instance; | ||
|
||
private SimpleFileWriter() { | ||
} | ||
|
||
public static SimpleFileWriter getInstance() { | ||
if (instance == null) { | ||
instance = new SimpleFileWriter(); | ||
} | ||
return instance; | ||
} | ||
|
||
public void saveDataIntoFile(String data, Path filePath) throws IOException { | ||
File tempFile = File.createTempFile(filePath.toString(), TMP); | ||
try (FileWriter writer = new FileWriter(tempFile, false)) { | ||
writer.write(data); | ||
} | ||
|
||
Files.move(tempFile.toPath(), filePath, REPLACE_EXISTING); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,4 +153,6 @@ void nodeIsAlreadyStopped_WhenStopNode_ThenShouldNotThrowError() throws Exceptio | |
fail(); | ||
} | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.