diff --git a/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy b/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy index b918fe87..00776e3c 100644 --- a/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy +++ b/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy @@ -50,10 +50,15 @@ class MuWireSettings { int responderCacheSize + boolean startChatServer int maxChatConnections boolean advertiseChat File chatWelcomeFile + + boolean allowMessages + boolean allowOnlyTrustedMessages + Set watchedDirectories float downloadSequentialRatio int hostClearInterval, hostHopelessInterval, hostRejectInterval, hostHopelessPurgeInterval @@ -136,12 +141,18 @@ class MuWireSettings { speedSmoothSeconds = Integer.valueOf(props.getProperty("speedSmoothSeconds","10")) totalUploadSlots = Integer.valueOf(props.getProperty("totalUploadSlots","-1")) uploadSlotsPerUser = Integer.valueOf(props.getProperty("uploadSlotsPerUser","-1")) + + // chat settings startChatServer = Boolean.valueOf(props.getProperty("startChatServer","false")) - maxChatConnections = Integer.valueOf(props.get("maxChatConnections", "-1")) + maxChatConnections = Integer.valueOf(props.getProperty("maxChatConnections", "-1")) advertiseChat = Boolean.valueOf(props.getProperty("advertiseChat","true")) String chatWelcomeProp = props.getProperty("chatWelcomeFile") if (chatWelcomeProp != null) chatWelcomeFile = new File(chatWelcomeProp) + + // messaging settings + allowMessages = Boolean.valueOf(props.getProperty("allowMessages","true")) + allowOnlyTrustedMessages = Boolean.valueOf(props.getProperty("allowOnlyTrustedMessages","false")) watchedDirectories = DataUtil.readEncodedSet(props, "watchedDirectories") watchedKeywords = DataUtil.readEncodedSet(props, "watchedKeywords") @@ -221,11 +232,18 @@ class MuWireSettings { props.setProperty("speedSmoothSeconds", String.valueOf(speedSmoothSeconds)) props.setProperty("totalUploadSlots", String.valueOf(totalUploadSlots)) props.setProperty("uploadSlotsPerUser", String.valueOf(uploadSlotsPerUser)) + + // chat settings props.setProperty("startChatServer", String.valueOf(startChatServer)) props.setProperty("maxChatConnectios", String.valueOf(maxChatConnections)) props.setProperty("advertiseChat", String.valueOf(advertiseChat)) if (chatWelcomeFile != null) props.setProperty("chatWelcomeFile", chatWelcomeFile.getAbsolutePath()) + + // messaging settings + props.setProperty("allowMessages", String.valueOf(allowMessages)) + props.setProperty("allowOnlyTrustedMessages", String.valueOf(allowOnlyTrustedMessages)) + DataUtil.writeEncodedSet(watchedDirectories, "watchedDirectories", props) DataUtil.writeEncodedSet(watchedKeywords, "watchedKeywords", props) diff --git a/core/src/main/groovy/com/muwire/core/connection/ConnectionAcceptor.groovy b/core/src/main/groovy/com/muwire/core/connection/ConnectionAcceptor.groovy index 35159c83..cfd623b1 100644 --- a/core/src/main/groovy/com/muwire/core/connection/ConnectionAcceptor.groovy +++ b/core/src/main/groovy/com/muwire/core/connection/ConnectionAcceptor.groovy @@ -685,6 +685,16 @@ class ConnectionAcceptor { byte [] ETTER = "ETTER\r\n".getBytes(StandardCharsets.US_ASCII) byte [] read = new byte[ETTER.length] + if (!settings.allowMessages) { + e.close() + return + } + + if (settings.allowOnlyTrustedMessages && trustService.getLevel(e.destination) != TrustLevel.TRUSTED) { + e.close() + return + } + DataInputStream dis = new DataInputStream(e.getInputStream()) try { dis.readFully(read)