Compare commits
63 Commits
muwire-0.6
...
muwire-0.6
Author | SHA1 | Date | |
---|---|---|---|
![]() |
fec81808e5 | ||
![]() |
4db890484d | ||
![]() |
dfd5e06889 | ||
![]() |
71da8e14da | ||
![]() |
7dc37e3e0d | ||
![]() |
3de058a078 | ||
![]() |
4d70c7adce | ||
![]() |
5b41106476 | ||
![]() |
6240b22e66 | ||
![]() |
0e26f5afd7 | ||
![]() |
114bc06dbb | ||
![]() |
5fa2f2753c | ||
![]() |
cacdd2a7a9 | ||
![]() |
d56f7c6184 | ||
![]() |
f7f4513109 | ||
![]() |
dd15d893ba | ||
![]() |
bf5ab9c82e | ||
![]() |
edd5a29b10 | ||
![]() |
38eb89f2f7 | ||
![]() |
73f1d64428 | ||
![]() |
bc1cae2d75 | ||
![]() |
a0ab07a7c0 | ||
![]() |
f875c379ce | ||
![]() |
0ce9784ccf | ||
![]() |
be82136e32 | ||
![]() |
7d25bb9364 | ||
![]() |
c6e98db9d4 | ||
![]() |
35a26e2a47 | ||
![]() |
beef4af329 | ||
![]() |
cec3c1bc0f | ||
![]() |
289b958784 | ||
![]() |
e9c554d717 | ||
![]() |
1875fcddb2 | ||
![]() |
bee6154fa9 | ||
![]() |
1f9b171021 | ||
![]() |
59c03be35e | ||
![]() |
621af96bdf | ||
![]() |
bcb7016202 | ||
![]() |
b1b2bcaef8 | ||
![]() |
eec007e83b | ||
![]() |
3d36351a6b | ||
![]() |
d57d2ccb71 | ||
![]() |
d91f15ee54 | ||
![]() |
6bc61c920d | ||
![]() |
146ed53e12 | ||
![]() |
8ebae1600b | ||
![]() |
18d19ca75e | ||
![]() |
29e499fe9d | ||
![]() |
3db167bade | ||
![]() |
bfe0ab7867 | ||
![]() |
1fbb1e7932 | ||
![]() |
0632336cd1 | ||
![]() |
aa221cd6dc | ||
![]() |
29b5c55328 | ||
![]() |
5e7f3587df | ||
![]() |
8afd387ca6 | ||
![]() |
5d16963d1c | ||
![]() |
6080c8b308 | ||
![]() |
915deb1dee | ||
![]() |
8afca3dc7f | ||
![]() |
f072d0343c | ||
![]() |
a549ad3d8d | ||
![]() |
b6f5ec7d22 |
10
README.md
10
README.md
@@ -4,7 +4,7 @@ MuWire is an easy to use file-sharing program which offers anonymity using [I2P
|
||||
|
||||
It is inspired by the LimeWire Gnutella client and developped by a former LimeWire developer.
|
||||
|
||||
The current stable release - 0.6.0 is avaiable for download at https://muwire.com. You can find technical documentation in the "doc" folder.
|
||||
The current stable release - 0.6.2 is avaiable for download at https://muwire.com. You can find technical documentation in the "doc" folder.
|
||||
|
||||
### Building
|
||||
|
||||
@@ -23,7 +23,7 @@ If you want to build binary bundles that do not depend on Java or I2P, see the h
|
||||
|
||||
### Running the GUI
|
||||
|
||||
After you build the application, look inside `gui/build/distributions`. Untar/unzip one of the `shadow` files and then run the jar contained inside by typing `java -jar gui-x.y.z.jar` in a terminal or command prompt.
|
||||
After you build the application, look inside `gui/build/distributions`. Untar/unzip one of the `shadow` files and then run the jar contained inside by typing `java -jar gui-x.y.z-all.jar` in a terminal or command prompt.
|
||||
|
||||
If you have an I2P router running on the same machine that is all you need to do. If you use a custom I2CP host and port, create a file `i2p.properties` and put `i2cp.tcp.host=<host>` and `i2cp.tcp.port=<port>` in there. On Windows that file should go into `%HOME%\AppData\Roaming\MuWire`, on Mac into `$HOME/Library/Application Support/MuWire` and on Linux `$HOME/.MuWire`
|
||||
|
||||
@@ -31,10 +31,14 @@ If you have an I2P router running on the same machine that is all you need to do
|
||||
|
||||
### Running the CLI
|
||||
|
||||
Look inside `cli-lanterna/build/distributions`. Untar/unzip one of the `shadow` files and then run the jar contained inside by typing `java -jar cli-lanterna-x.y.z.jar` in a terminal. The CLI will ask you about the router host and port on startup, no need to edit any files. However, the CLI does not have an options window yet, so if you need to change any options you will need to edit the configuration files. The CLI options are documented here https://github.com/zlatinb/muwire/wiki/CLI-Configuration-Options
|
||||
Look inside `cli-lanterna/build/distributions`. Untar/unzip one of the `shadow` files and then run the jar contained inside by typing `java -jar cli-lanterna-x.y.z-all.jar` in a terminal. The CLI will ask you about the router host and port on startup, no need to edit any files. However, the CLI does not have an options window yet, so if you need to change any options you will need to edit the configuration files. The CLI options are documented here https://github.com/zlatinb/muwire/wiki/CLI-Configuration-Options
|
||||
|
||||
The CLI is under active development and doesn't have all the features of the GUI.
|
||||
|
||||
### Web UI
|
||||
|
||||
If you are a Grails/Scala/JRuby/Kotlin developer and are interested in building a Web UI for MuWire, please get in touch. The MuWire core is written in Groovy and should be easy to integrate with any JVM-based language.
|
||||
|
||||
### GPG Fingerprint
|
||||
|
||||
```
|
||||
|
@@ -6,7 +6,7 @@ buildscript {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4'
|
||||
classpath 'com.github.jengelman.gradle.plugins:shadow:5.2.0'
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -32,7 +32,7 @@ import com.muwire.core.UILoadedEvent
|
||||
import com.muwire.core.files.AllFilesLoadedEvent
|
||||
|
||||
class CliLanterna {
|
||||
private static final String MW_VERSION = "0.6.2"
|
||||
private static final String MW_VERSION = "0.6.5"
|
||||
|
||||
private static volatile Core core
|
||||
|
||||
|
@@ -6,7 +6,7 @@ buildscript {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4'
|
||||
classpath 'com.github.jengelman.gradle.plugins:shadow:5.2.0'
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -3,6 +3,12 @@ package com.muwire.core
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
import com.muwire.core.chat.ChatDisconnectionEvent
|
||||
import com.muwire.core.chat.ChatManager
|
||||
import com.muwire.core.chat.ChatMessageEvent
|
||||
import com.muwire.core.chat.ChatServer
|
||||
import com.muwire.core.chat.UIConnectChatEvent
|
||||
import com.muwire.core.chat.UIDisconnectChatEvent
|
||||
import com.muwire.core.connection.ConnectionAcceptor
|
||||
import com.muwire.core.connection.ConnectionEstablisher
|
||||
import com.muwire.core.connection.ConnectionEvent
|
||||
@@ -105,6 +111,8 @@ public class Core {
|
||||
final UploadManager uploadManager
|
||||
final ContentManager contentManager
|
||||
final CertificateManager certificateManager
|
||||
final ChatServer chatServer
|
||||
final ChatManager chatManager
|
||||
|
||||
private final Router router
|
||||
|
||||
@@ -278,8 +286,16 @@ public class Core {
|
||||
CertificateClient certificateClient = new CertificateClient(eventBus, i2pConnector)
|
||||
eventBus.register(UIFetchCertificatesEvent.class, certificateClient)
|
||||
|
||||
log.info("initializing chat server")
|
||||
chatServer = new ChatServer(eventBus, props, trustService, me, spk)
|
||||
eventBus.with {
|
||||
register(ChatMessageEvent.class, chatServer)
|
||||
register(ChatDisconnectionEvent.class, chatServer)
|
||||
register(TrustEvent.class, chatServer)
|
||||
}
|
||||
|
||||
log.info "initializing results sender"
|
||||
ResultsSender resultsSender = new ResultsSender(eventBus, i2pConnector, me, props, certificateManager)
|
||||
ResultsSender resultsSender = new ResultsSender(eventBus, i2pConnector, me, props, certificateManager, chatServer)
|
||||
|
||||
log.info "initializing search manager"
|
||||
SearchManager searchManager = new SearchManager(eventBus, me, resultsSender)
|
||||
@@ -302,11 +318,21 @@ public class Core {
|
||||
log.info("initializing connection establisher")
|
||||
connectionEstablisher = new ConnectionEstablisher(eventBus, i2pConnector, props, connectionManager, hostCache)
|
||||
|
||||
|
||||
log.info("initializing chat manager")
|
||||
chatManager = new ChatManager(eventBus, me, i2pConnector, trustService, props)
|
||||
eventBus.with {
|
||||
register(UIConnectChatEvent.class, chatManager)
|
||||
register(UIDisconnectChatEvent.class, chatManager)
|
||||
register(ChatMessageEvent.class, chatManager)
|
||||
register(ChatDisconnectionEvent.class, chatManager)
|
||||
}
|
||||
|
||||
log.info("initializing acceptor")
|
||||
I2PAcceptor i2pAcceptor = new I2PAcceptor(socketManager)
|
||||
connectionAcceptor = new ConnectionAcceptor(eventBus, connectionManager, props,
|
||||
i2pAcceptor, hostCache, trustService, searchManager, uploadManager, fileManager, connectionEstablisher,
|
||||
certificateManager)
|
||||
certificateManager, chatServer)
|
||||
|
||||
log.info("initializing directory watcher")
|
||||
directoryWatcher = new DirectoryWatcher(eventBus, fileManager, home, props)
|
||||
@@ -358,9 +384,9 @@ public class Core {
|
||||
saveMuSettings()
|
||||
log.info("shutting down trust subscriber")
|
||||
trustSubscriber.stop()
|
||||
log.info("shutting down download manageer")
|
||||
log.info("shutting down download manager")
|
||||
downloadManager.shutdown()
|
||||
log.info("shutting down connection acceeptor")
|
||||
log.info("shutting down connection acceptor")
|
||||
connectionAcceptor.stop()
|
||||
log.info("shutting down connection establisher")
|
||||
connectionEstablisher.stop()
|
||||
@@ -368,6 +394,10 @@ public class Core {
|
||||
directoryWatcher.stop()
|
||||
log.info("shutting down cache client")
|
||||
cacheClient.stop()
|
||||
log.info("shutting down chat server")
|
||||
chatServer.stop()
|
||||
log.info("shutting down chat manager")
|
||||
chatManager.shutdown()
|
||||
log.info("shutting down connection manager")
|
||||
connectionManager.shutdown()
|
||||
if (router != null) {
|
||||
@@ -406,7 +436,7 @@ public class Core {
|
||||
}
|
||||
}
|
||||
|
||||
Core core = new Core(props, home, "0.6.2")
|
||||
Core core = new Core(props, home, "0.6.5")
|
||||
core.startServices()
|
||||
|
||||
// ... at the end, sleep or execute script
|
||||
|
@@ -31,6 +31,9 @@ class MuWireSettings {
|
||||
boolean shareHiddenFiles
|
||||
boolean searchComments
|
||||
boolean browseFiles
|
||||
boolean startChatServer
|
||||
int maxChatConnections
|
||||
boolean advertiseChat
|
||||
Set<String> watchedDirectories
|
||||
float downloadSequentialRatio
|
||||
int hostClearInterval, hostHopelessInterval, hostRejectInterval
|
||||
@@ -79,7 +82,10 @@ class MuWireSettings {
|
||||
speedSmoothSeconds = Integer.valueOf(props.getProperty("speedSmoothSeconds","60"))
|
||||
totalUploadSlots = Integer.valueOf(props.getProperty("totalUploadSlots","-1"))
|
||||
uploadSlotsPerUser = Integer.valueOf(props.getProperty("uploadSlotsPerUser","-1"))
|
||||
|
||||
startChatServer = Boolean.valueOf(props.getProperty("startChatServer","false"))
|
||||
maxChatConnections = Integer.valueOf(props.get("maxChatConnections", "-1"))
|
||||
advertiseChat = Boolean.valueOf(props.getProperty("advertiseChat","true"))
|
||||
|
||||
watchedDirectories = DataUtil.readEncodedSet(props, "watchedDirectories")
|
||||
watchedKeywords = DataUtil.readEncodedSet(props, "watchedKeywords")
|
||||
watchedRegexes = DataUtil.readEncodedSet(props, "watchedRegexes")
|
||||
@@ -127,6 +133,9 @@ class MuWireSettings {
|
||||
props.setProperty("speedSmoothSeconds", String.valueOf(speedSmoothSeconds))
|
||||
props.setProperty("totalUploadSlots", String.valueOf(totalUploadSlots))
|
||||
props.setProperty("uploadSlotsPerUser", String.valueOf(uploadSlotsPerUser))
|
||||
props.setProperty("startChatServer", String.valueOf(startChatServer))
|
||||
props.setProperty("maxChatConnectios", String.valueOf(maxChatConnections))
|
||||
props.setProperty("advertiseChat", String.valueOf(advertiseChat))
|
||||
|
||||
DataUtil.writeEncodedSet(watchedDirectories, "watchedDirectories", props)
|
||||
DataUtil.writeEncodedSet(watchedKeywords, "watchedKeywords", props)
|
||||
|
20
core/src/main/groovy/com/muwire/core/chat/ChatAction.java
Normal file
20
core/src/main/groovy/com/muwire/core/chat/ChatAction.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package com.muwire.core.chat;
|
||||
|
||||
enum ChatAction {
|
||||
JOIN(true, false, true),
|
||||
LEAVE(false, false, true),
|
||||
SAY(false, false, true),
|
||||
LIST(true, true, true),
|
||||
HELP(true, true, true),
|
||||
INFO(true, true, true),
|
||||
JOINED(true, true, false);
|
||||
|
||||
final boolean console;
|
||||
final boolean stateless;
|
||||
final boolean user;
|
||||
ChatAction(boolean console, boolean stateless, boolean user) {
|
||||
this.console = console;
|
||||
this.stateless = stateless;
|
||||
this.user = user;
|
||||
}
|
||||
}
|
119
core/src/main/groovy/com/muwire/core/chat/ChatClient.groovy
Normal file
119
core/src/main/groovy/com/muwire/core/chat/ChatClient.groovy
Normal file
@@ -0,0 +1,119 @@
|
||||
package com.muwire.core.chat
|
||||
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.util.concurrent.Executor
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
import com.muwire.core.Constants
|
||||
import com.muwire.core.EventBus
|
||||
import com.muwire.core.MuWireSettings
|
||||
import com.muwire.core.Persona
|
||||
import com.muwire.core.connection.Endpoint
|
||||
import com.muwire.core.connection.I2PConnector
|
||||
import com.muwire.core.trust.TrustService
|
||||
import com.muwire.core.util.DataUtil
|
||||
|
||||
import groovy.util.logging.Log
|
||||
|
||||
@Log
|
||||
class ChatClient implements Closeable {
|
||||
|
||||
private static final long REJECTION_BACKOFF = 60 * 1000
|
||||
|
||||
private static final Executor CONNECTOR = Executors.newCachedThreadPool()
|
||||
|
||||
private final I2PConnector connector
|
||||
private final EventBus eventBus
|
||||
private final Persona host, me
|
||||
private final TrustService trustService
|
||||
private final MuWireSettings settings
|
||||
|
||||
private volatile ChatConnection connection
|
||||
private volatile boolean connectInProgress
|
||||
private volatile long lastRejectionTime
|
||||
private volatile Thread connectThread
|
||||
|
||||
ChatClient(I2PConnector connector, EventBus eventBus, Persona host, Persona me, TrustService trustService,
|
||||
MuWireSettings settings) {
|
||||
this.connector = connector
|
||||
this.eventBus = eventBus
|
||||
this.host = host
|
||||
this.me = me
|
||||
this.trustService = trustService
|
||||
this.settings = settings
|
||||
}
|
||||
|
||||
void connectIfNeeded() {
|
||||
if (connection != null || connectInProgress || (System.currentTimeMillis() - lastRejectionTime < REJECTION_BACKOFF))
|
||||
return
|
||||
CONNECTOR.execute({connect()})
|
||||
}
|
||||
|
||||
private void connect() {
|
||||
connectInProgress = true
|
||||
connectThread = Thread.currentThread()
|
||||
Endpoint endpoint = null
|
||||
try {
|
||||
eventBus.publish(new ChatConnectionEvent(status : ChatConnectionAttemptStatus.CONNECTING, persona : host))
|
||||
endpoint = connector.connect(host.destination)
|
||||
DataOutputStream dos = new DataOutputStream(endpoint.getOutputStream())
|
||||
DataInputStream dis = new DataInputStream(endpoint.getInputStream())
|
||||
|
||||
dos.with {
|
||||
write("IRC\r\n".getBytes(StandardCharsets.US_ASCII))
|
||||
write("Version:${Constants.CHAT_VERSION}\r\n".getBytes(StandardCharsets.US_ASCII))
|
||||
write("Persona:${me.toBase64()}\r\n".getBytes(StandardCharsets.US_ASCII))
|
||||
write("\r\n".getBytes(StandardCharsets.US_ASCII))
|
||||
flush()
|
||||
}
|
||||
|
||||
String codeString = DataUtil.readTillRN(dis)
|
||||
int code = Integer.parseInt(codeString.split(" ")[0])
|
||||
|
||||
if (code == 429) {
|
||||
eventBus.publish(new ChatConnectionEvent(status : ChatConnectionAttemptStatus.REJECTED, persona : host))
|
||||
endpoint.close()
|
||||
lastRejectionTime = System.currentTimeMillis()
|
||||
return
|
||||
}
|
||||
|
||||
if (code != 200)
|
||||
throw new Exception("unknown code $code")
|
||||
|
||||
Map<String,String> headers = DataUtil.readAllHeaders(dis)
|
||||
if (!headers.containsKey('Version'))
|
||||
throw new Exception("Version header missing")
|
||||
|
||||
int version = Integer.parseInt(headers['Version'])
|
||||
if (version != Constants.CHAT_VERSION)
|
||||
throw new Exception("Unknown chat version $version")
|
||||
|
||||
connection = new ChatConnection(eventBus, endpoint, host, false, trustService, settings)
|
||||
connection.start()
|
||||
eventBus.publish(new ChatConnectionEvent(status : ChatConnectionAttemptStatus.SUCCESSFUL, persona : host,
|
||||
connection : connection))
|
||||
} catch (Exception e) {
|
||||
eventBus.publish(new ChatConnectionEvent(status : ChatConnectionAttemptStatus.FAILED, persona : host))
|
||||
endpoint?.close()
|
||||
} finally {
|
||||
connectInProgress = false
|
||||
connectThread = null
|
||||
}
|
||||
}
|
||||
|
||||
void disconnected() {
|
||||
connectInProgress = false
|
||||
connection = null
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
connectThread?.interrupt()
|
||||
connection?.close()
|
||||
eventBus.publish(new ChatConnectionEvent(status : ChatConnectionAttemptStatus.DISCONNECTED, persona : host))
|
||||
}
|
||||
|
||||
void ping() {
|
||||
connection?.sendPing()
|
||||
}
|
||||
}
|
28
core/src/main/groovy/com/muwire/core/chat/ChatCommand.groovy
Normal file
28
core/src/main/groovy/com/muwire/core/chat/ChatCommand.groovy
Normal file
@@ -0,0 +1,28 @@
|
||||
package com.muwire.core.chat
|
||||
|
||||
class ChatCommand {
|
||||
private final ChatAction action
|
||||
private final String payload
|
||||
final String source
|
||||
ChatCommand(String source) {
|
||||
if (source.charAt(0) != '/')
|
||||
throw new Exception("command doesn't start with / $source")
|
||||
|
||||
int position = 1
|
||||
StringBuilder sb = new StringBuilder()
|
||||
while(position < source.length()) {
|
||||
char c = source.charAt(position)
|
||||
if (c == ' ')
|
||||
break
|
||||
sb.append(c)
|
||||
position++
|
||||
}
|
||||
String command = sb.toString().toUpperCase()
|
||||
action = ChatAction.valueOf(command)
|
||||
if (position < source.length())
|
||||
payload = source.substring(position + 1)
|
||||
else
|
||||
payload = ""
|
||||
this.source = source
|
||||
}
|
||||
}
|
278
core/src/main/groovy/com/muwire/core/chat/ChatConnection.groovy
Normal file
278
core/src/main/groovy/com/muwire/core/chat/ChatConnection.groovy
Normal file
@@ -0,0 +1,278 @@
|
||||
package com.muwire.core.chat
|
||||
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.util.concurrent.BlockingQueue
|
||||
import java.util.concurrent.LinkedBlockingQueue
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import java.util.logging.Level
|
||||
|
||||
import com.muwire.core.Constants
|
||||
import com.muwire.core.EventBus
|
||||
import com.muwire.core.MuWireSettings
|
||||
import com.muwire.core.Persona
|
||||
import com.muwire.core.connection.Endpoint
|
||||
import com.muwire.core.trust.TrustLevel
|
||||
import com.muwire.core.trust.TrustService
|
||||
|
||||
import groovy.json.JsonOutput
|
||||
import groovy.json.JsonSlurper
|
||||
import groovy.util.logging.Log
|
||||
import net.i2p.crypto.DSAEngine
|
||||
import net.i2p.data.Base64
|
||||
import net.i2p.data.Signature
|
||||
import net.i2p.data.SigningPrivateKey
|
||||
|
||||
@Log
|
||||
class ChatConnection implements ChatLink {
|
||||
|
||||
private static final long PING_INTERVAL = 20000
|
||||
private static final long MAX_CHAT_AGE = 5 * 60 * 1000
|
||||
|
||||
private final EventBus eventBus
|
||||
private final Endpoint endpoint
|
||||
private final Persona persona
|
||||
private final boolean incoming
|
||||
private final TrustService trustService
|
||||
private final MuWireSettings settings
|
||||
|
||||
private final AtomicBoolean running = new AtomicBoolean()
|
||||
private final BlockingQueue messages = new LinkedBlockingQueue()
|
||||
private final Thread reader, writer
|
||||
private final LinkedList<Long> timestamps = new LinkedList<>()
|
||||
private final BlockingQueue incomingEvents = new LinkedBlockingQueue()
|
||||
|
||||
private final DataInputStream dis
|
||||
private final DataOutputStream dos
|
||||
|
||||
private final JsonSlurper slurper = new JsonSlurper()
|
||||
|
||||
private volatile long lastPingSentTime
|
||||
|
||||
ChatConnection(EventBus eventBus, Endpoint endpoint, Persona persona, boolean incoming,
|
||||
TrustService trustService, MuWireSettings settings) {
|
||||
this.eventBus = eventBus
|
||||
this.endpoint = endpoint
|
||||
this.persona = persona
|
||||
this.incoming = incoming
|
||||
this.trustService = trustService
|
||||
this.settings = settings
|
||||
|
||||
this.dis = new DataInputStream(endpoint.getInputStream())
|
||||
this.dos = new DataOutputStream(endpoint.getOutputStream())
|
||||
|
||||
this.reader = new Thread({readLoop()} as Runnable)
|
||||
this.reader.setName("reader-${persona.getHumanReadableName()}")
|
||||
this.reader.setDaemon(true)
|
||||
|
||||
this.writer = new Thread({writeLoop()} as Runnable)
|
||||
this.writer.setName("writer-${persona.getHumanReadableName()}")
|
||||
this.writer.setDaemon(true)
|
||||
}
|
||||
|
||||
void start() {
|
||||
if (!running.compareAndSet(false, true)) {
|
||||
log.log(Level.WARNING,"${persona.getHumanReadableName()} already running", new Exception())
|
||||
return
|
||||
}
|
||||
reader.start()
|
||||
writer.start()
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUp() {
|
||||
running.get()
|
||||
}
|
||||
|
||||
@Override
|
||||
public Persona getPersona() {
|
||||
persona
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
if (!running.compareAndSet(true, false)) {
|
||||
log.log(Level.WARNING,"${persona.getHumanReadableName()} already closed", new Exception())
|
||||
return
|
||||
}
|
||||
log.info("Closing "+persona.getHumanReadableName())
|
||||
reader.interrupt()
|
||||
writer.interrupt()
|
||||
endpoint.close()
|
||||
eventBus.publish(new ChatDisconnectionEvent(persona : persona))
|
||||
}
|
||||
|
||||
private void readLoop() {
|
||||
try {
|
||||
while(running.get())
|
||||
read()
|
||||
} catch( InterruptedException | SocketTimeoutException ignored) {
|
||||
} catch (Exception e) {
|
||||
log.log(Level.WARNING,"unhandled exception in reader", e)
|
||||
} finally {
|
||||
close()
|
||||
}
|
||||
}
|
||||
|
||||
private void writeLoop() {
|
||||
try {
|
||||
while(running.get()) {
|
||||
def message = messages.take()
|
||||
write(message)
|
||||
}
|
||||
} catch (InterruptedException ignore) {
|
||||
} catch (Exception e) {
|
||||
log.log(Level.WARNING,"unhandled exception in writer",e)
|
||||
} finally {
|
||||
close()
|
||||
}
|
||||
}
|
||||
|
||||
private void read() {
|
||||
int length = dis.readUnsignedShort()
|
||||
byte [] payload = new byte[length]
|
||||
dis.readFully(payload)
|
||||
def json = slurper.parse(payload)
|
||||
if (json.type == null)
|
||||
throw new Exception("missing json type")
|
||||
switch(json.type) {
|
||||
case "Ping" : break // just ignore
|
||||
case "Chat" : handleChat(json); break
|
||||
case "Leave": handleLeave(json); break
|
||||
default :
|
||||
throw new Exception("unknown json type ${json.type}")
|
||||
}
|
||||
}
|
||||
|
||||
private void write(Object message) {
|
||||
byte [] payload = JsonOutput.toJson(message).bytes
|
||||
dos.with {
|
||||
writeShort(payload.length)
|
||||
write(payload)
|
||||
flush()
|
||||
}
|
||||
}
|
||||
|
||||
void sendPing() {
|
||||
long now = System.currentTimeMillis()
|
||||
if (now - lastPingSentTime < PING_INTERVAL)
|
||||
return
|
||||
def ping = [:]
|
||||
ping.type = "Ping"
|
||||
ping.version = 1
|
||||
messages.put(ping)
|
||||
lastPingSentTime = now
|
||||
}
|
||||
|
||||
private void handleChat(def json) {
|
||||
UUID uuid = UUID.fromString(json.uuid)
|
||||
Persona host = fromString(json.host)
|
||||
Persona sender = fromString(json.sender)
|
||||
long chatTime = json.chatTime
|
||||
String room = json.room
|
||||
String payload = json.payload
|
||||
byte [] sig = Base64.decode(json.sig)
|
||||
|
||||
if (!verify(uuid,host,sender,chatTime,room,payload,sig)) {
|
||||
log.warning("chat didn't verify")
|
||||
return
|
||||
}
|
||||
if (incoming) {
|
||||
if (sender.destination != endpoint.destination) {
|
||||
log.warning("Sender destination mismatch, dropping message")
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if (host.destination != endpoint.destination) {
|
||||
log.warning("Host destination mismatch, dropping message")
|
||||
return
|
||||
}
|
||||
}
|
||||
if (System.currentTimeMillis() - chatTime > MAX_CHAT_AGE) {
|
||||
log.warning("Chat too old, dropping")
|
||||
return
|
||||
}
|
||||
switch(trustService.getLevel(sender.destination)) {
|
||||
case TrustLevel.TRUSTED : break
|
||||
case TrustLevel.NEUTRAL :
|
||||
if (!settings.allowUntrusted)
|
||||
return
|
||||
else
|
||||
break
|
||||
case TrustLevel.DISTRUSTED :
|
||||
return
|
||||
}
|
||||
def event = new ChatMessageEvent( uuid : uuid, payload : payload, sender : sender,
|
||||
host : host, room : room, chatTime : chatTime, sig : sig)
|
||||
eventBus.publish(event)
|
||||
if (!incoming)
|
||||
incomingEvents.put(event)
|
||||
}
|
||||
|
||||
private void handleLeave(def json) {
|
||||
Persona leaver = fromString(json.persona)
|
||||
eventBus.publish(new UserDisconnectedEvent(user : leaver, host : persona))
|
||||
incomingEvents.put(leaver)
|
||||
}
|
||||
|
||||
private static Persona fromString(String base64) {
|
||||
new Persona(new ByteArrayInputStream(Base64.decode(base64)))
|
||||
}
|
||||
|
||||
private static boolean verify(UUID uuid, Persona host, Persona sender, long chatTime,
|
||||
String room, String payload, byte []sig) {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream()
|
||||
DataOutputStream daos = new DataOutputStream(baos)
|
||||
daos.write(uuid.toString().bytes)
|
||||
host.write(daos)
|
||||
sender.write(daos)
|
||||
daos.writeLong(chatTime)
|
||||
daos.write(room.getBytes(StandardCharsets.UTF_8))
|
||||
daos.write(payload.getBytes(StandardCharsets.UTF_8))
|
||||
daos.close()
|
||||
byte [] signed = baos.toByteArray()
|
||||
def spk = sender.destination.getSigningPublicKey()
|
||||
def signature = new Signature(Constants.SIG_TYPE, sig)
|
||||
DSAEngine.getInstance().verifySignature(signature, signed, spk)
|
||||
}
|
||||
|
||||
public static byte[] sign(UUID uuid, long chatTime, String room, String words, Persona sender, Persona host, SigningPrivateKey spk) {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream()
|
||||
DataOutputStream daos = new DataOutputStream(baos)
|
||||
daos.with {
|
||||
write(uuid.toString().bytes)
|
||||
host.write(daos)
|
||||
sender.write(daos)
|
||||
writeLong(chatTime)
|
||||
write(room.getBytes(StandardCharsets.UTF_8))
|
||||
write(words.getBytes(StandardCharsets.UTF_8))
|
||||
close()
|
||||
}
|
||||
byte [] payload = baos.toByteArray()
|
||||
Signature sig = DSAEngine.getInstance().sign(payload, spk)
|
||||
sig.getData()
|
||||
}
|
||||
|
||||
void sendChat(ChatMessageEvent e) {
|
||||
def chat = [:]
|
||||
chat.type = "Chat"
|
||||
chat.uuid = e.uuid.toString()
|
||||
chat.host = e.host.toBase64()
|
||||
chat.sender = e.sender.toBase64()
|
||||
chat.chatTime = e.chatTime
|
||||
chat.room = e.room
|
||||
chat.payload = e.payload
|
||||
chat.sig = Base64.encode(e.sig)
|
||||
messages.put(chat)
|
||||
}
|
||||
|
||||
void sendLeave(Persona p) {
|
||||
def leave = [:]
|
||||
leave.type = "Leave"
|
||||
leave.persona = p.toBase64()
|
||||
messages.put(leave)
|
||||
}
|
||||
|
||||
public Object nextEvent() {
|
||||
incomingEvents.take()
|
||||
}
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
package com.muwire.core.chat;
|
||||
|
||||
public enum ChatConnectionAttemptStatus {
|
||||
CONNECTING, SUCCESSFUL, REJECTED, FAILED, DISCONNECTED
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
package com.muwire.core.chat
|
||||
|
||||
import com.muwire.core.Event
|
||||
import com.muwire.core.Persona
|
||||
|
||||
class ChatConnectionEvent extends Event {
|
||||
ChatConnectionAttemptStatus status
|
||||
Persona persona
|
||||
ChatLink connection
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
package com.muwire.core.chat
|
||||
|
||||
import com.muwire.core.Event
|
||||
import com.muwire.core.Persona
|
||||
|
||||
class ChatDisconnectionEvent extends Event {
|
||||
Persona persona
|
||||
}
|
14
core/src/main/groovy/com/muwire/core/chat/ChatLink.java
Normal file
14
core/src/main/groovy/com/muwire/core/chat/ChatLink.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package com.muwire.core.chat;
|
||||
|
||||
import java.io.Closeable;
|
||||
|
||||
import com.muwire.core.Persona;
|
||||
|
||||
public interface ChatLink extends Closeable {
|
||||
public Persona getPersona();
|
||||
public boolean isUp();
|
||||
public void sendChat(ChatMessageEvent e);
|
||||
public void sendLeave(Persona p);
|
||||
public void sendPing();
|
||||
public Object nextEvent() throws InterruptedException;
|
||||
}
|
73
core/src/main/groovy/com/muwire/core/chat/ChatManager.groovy
Normal file
73
core/src/main/groovy/com/muwire/core/chat/ChatManager.groovy
Normal file
@@ -0,0 +1,73 @@
|
||||
package com.muwire.core.chat
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
import com.muwire.core.EventBus
|
||||
import com.muwire.core.MuWireSettings
|
||||
import com.muwire.core.Persona
|
||||
import com.muwire.core.connection.I2PConnector
|
||||
import com.muwire.core.trust.TrustService
|
||||
|
||||
class ChatManager {
|
||||
private final EventBus eventBus
|
||||
private final Persona me
|
||||
private final I2PConnector connector
|
||||
private final TrustService trustService
|
||||
private final MuWireSettings settings
|
||||
|
||||
private final Map<Persona, ChatClient> clients = new ConcurrentHashMap<>()
|
||||
|
||||
ChatManager(EventBus eventBus, Persona me, I2PConnector connector, TrustService trustService,
|
||||
MuWireSettings settings) {
|
||||
this.eventBus = eventBus
|
||||
this.me = me
|
||||
this.connector = connector
|
||||
this.trustService = trustService
|
||||
this.settings = settings
|
||||
|
||||
Timer timer = new Timer("chat-connector", true)
|
||||
timer.schedule({connect()} as TimerTask, 1000, 1000)
|
||||
}
|
||||
|
||||
void onUIConnectChatEvent(UIConnectChatEvent e) {
|
||||
if (e.host == me) {
|
||||
eventBus.publish(new ChatConnectionEvent(status : ChatConnectionAttemptStatus.SUCCESSFUL,
|
||||
persona : me, connection : LocalChatLink.INSTANCE))
|
||||
} else {
|
||||
ChatClient client = new ChatClient(connector, eventBus, e.host, me, trustService, settings)
|
||||
clients.put(e.host, client)
|
||||
}
|
||||
}
|
||||
|
||||
void onUIDisconnectChatEvent(UIDisconnectChatEvent e) {
|
||||
if (e.host == me)
|
||||
return
|
||||
ChatClient client = clients.remove(e.host)
|
||||
client?.close()
|
||||
}
|
||||
|
||||
void onChatMessageEvent(ChatMessageEvent e) {
|
||||
if (e.host == me)
|
||||
return
|
||||
if (e.sender != me)
|
||||
return
|
||||
clients[e.host]?.connection?.sendChat(e)
|
||||
}
|
||||
|
||||
void onChatDisconnectionEvent(ChatDisconnectionEvent e) {
|
||||
clients[e.persona]?.disconnected()
|
||||
}
|
||||
|
||||
private void connect() {
|
||||
clients.each { k, v ->
|
||||
v.connectIfNeeded()
|
||||
v.ping()
|
||||
}
|
||||
}
|
||||
|
||||
void shutdown() {
|
||||
clients.each { k, v ->
|
||||
v.close()
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
package com.muwire.core.chat
|
||||
|
||||
import com.muwire.core.Event
|
||||
import com.muwire.core.Persona
|
||||
|
||||
class ChatMessageEvent extends Event {
|
||||
UUID uuid
|
||||
String payload
|
||||
Persona sender, host
|
||||
String room
|
||||
long chatTime
|
||||
byte [] sig
|
||||
}
|
302
core/src/main/groovy/com/muwire/core/chat/ChatServer.groovy
Normal file
302
core/src/main/groovy/com/muwire/core/chat/ChatServer.groovy
Normal file
@@ -0,0 +1,302 @@
|
||||
package com.muwire.core.chat
|
||||
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import java.util.logging.Level
|
||||
import java.util.stream.Collectors
|
||||
|
||||
import com.muwire.core.Constants
|
||||
import com.muwire.core.EventBus
|
||||
import com.muwire.core.MuWireSettings
|
||||
import com.muwire.core.Persona
|
||||
import com.muwire.core.connection.Endpoint
|
||||
import com.muwire.core.trust.TrustEvent
|
||||
import com.muwire.core.trust.TrustLevel
|
||||
import com.muwire.core.trust.TrustService
|
||||
import com.muwire.core.util.DataUtil
|
||||
|
||||
import groovy.util.logging.Log
|
||||
import net.i2p.data.Base64
|
||||
import net.i2p.data.Destination
|
||||
import net.i2p.data.SigningPrivateKey
|
||||
import net.i2p.util.ConcurrentHashSet
|
||||
|
||||
@Log
|
||||
class ChatServer {
|
||||
public static final String CONSOLE = "__CONSOLE__"
|
||||
private final EventBus eventBus
|
||||
private final MuWireSettings settings
|
||||
private final TrustService trustService
|
||||
private final Persona me
|
||||
private final SigningPrivateKey spk
|
||||
|
||||
private final Map<Destination, ChatLink> connections = new ConcurrentHashMap()
|
||||
private final Map<String, Set<Persona>> rooms = new ConcurrentHashMap<>()
|
||||
private final Map<Persona, Set<String>> memberships = new ConcurrentHashMap<>()
|
||||
|
||||
private final AtomicBoolean running = new AtomicBoolean()
|
||||
|
||||
ChatServer(EventBus eventBus, MuWireSettings settings, TrustService trustService, Persona me, SigningPrivateKey spk) {
|
||||
this.eventBus = eventBus
|
||||
this.settings = settings
|
||||
this.trustService = trustService
|
||||
this.me = me
|
||||
this.spk = spk
|
||||
|
||||
Timer timer = new Timer("chat-server-pinger", true)
|
||||
timer.schedule({sendPings()} as TimerTask, 1000, 1000)
|
||||
}
|
||||
|
||||
public void start() {
|
||||
running.set(true)
|
||||
connections.put(me.destination, LocalChatLink.INSTANCE)
|
||||
joinRoom(me, CONSOLE)
|
||||
echo("/SAY Welcome to my chat server! Type /HELP for list of available commands.",me.destination)
|
||||
}
|
||||
|
||||
private void sendPings() {
|
||||
connections.each { k,v ->
|
||||
v.sendPing()
|
||||
}
|
||||
}
|
||||
|
||||
public void handle(Endpoint endpoint) {
|
||||
InputStream is = endpoint.getInputStream()
|
||||
OutputStream os = endpoint.getOutputStream()
|
||||
|
||||
Map<String, String> headers = DataUtil.readAllHeaders(is)
|
||||
|
||||
if (!headers.containsKey("Version"))
|
||||
throw new Exception("Version header missing")
|
||||
|
||||
int version = Integer.parseInt(headers['Version'])
|
||||
if (version != Constants.CHAT_VERSION)
|
||||
throw new Exception("Unknown chat version $version")
|
||||
|
||||
if (!headers.containsKey('Persona'))
|
||||
throw new Exception("Persona header missing")
|
||||
|
||||
Persona client = new Persona(new ByteArrayInputStream(Base64.decode(headers['Persona'])))
|
||||
if (client.destination != endpoint.destination)
|
||||
throw new Exception("Client destination mismatch")
|
||||
|
||||
if (!running.get()) {
|
||||
os.write("400 Chat Not Enabled\r\n\r\n".getBytes(StandardCharsets.US_ASCII))
|
||||
os.close()
|
||||
endpoint.close()
|
||||
return
|
||||
}
|
||||
|
||||
if (connections.containsKey(client.destination) || connections.size() == settings.maxChatConnections) {
|
||||
os.write("429 Rejected\r\n\r\n".getBytes(StandardCharsets.US_ASCII))
|
||||
os.close()
|
||||
endpoint.close()
|
||||
return
|
||||
}
|
||||
|
||||
os.with {
|
||||
write("200 OK\r\n".getBytes(StandardCharsets.US_ASCII))
|
||||
write("Version:${Constants.CHAT_VERSION}\r\n".getBytes(StandardCharsets.US_ASCII))
|
||||
write("\r\n".getBytes(StandardCharsets.US_ASCII))
|
||||
flush()
|
||||
}
|
||||
|
||||
ChatConnection connection = new ChatConnection(eventBus, endpoint, client, true, trustService, settings)
|
||||
connections.put(endpoint.destination, connection)
|
||||
joinRoom(client, CONSOLE)
|
||||
connection.start()
|
||||
echo("/SAY Welcome to my chat server! Type /HELP for help on available commands",connection.endpoint.destination)
|
||||
}
|
||||
|
||||
void onChatDisconnectionEvent(ChatDisconnectionEvent e) {
|
||||
ChatConnection con = connections.remove(e.persona.destination)
|
||||
if (con == null)
|
||||
return
|
||||
|
||||
Set<String> rooms = memberships.get(e.persona)
|
||||
if (rooms != null) {
|
||||
rooms.each {
|
||||
leaveRoom(e.persona, it)
|
||||
}
|
||||
}
|
||||
connections.each { k, v ->
|
||||
v.sendLeave(e.persona)
|
||||
}
|
||||
}
|
||||
|
||||
void onTrustEvent(TrustEvent e) {
|
||||
if (e.level == TrustLevel.TRUSTED)
|
||||
return
|
||||
if (settings.allowUntrusted && e.level == TrustLevel.NEUTRAL)
|
||||
return
|
||||
|
||||
ChatConnection connection = connections.remove(e.persona.destination)
|
||||
connection?.close()
|
||||
}
|
||||
|
||||
private void joinRoom(Persona p, String room) {
|
||||
Set<Persona> existing = rooms.get(room)
|
||||
if (existing == null) {
|
||||
existing = new ConcurrentHashSet<>()
|
||||
rooms.put(room, existing)
|
||||
}
|
||||
existing.add(p)
|
||||
|
||||
Set<String> membership = memberships.get(p)
|
||||
if (membership == null) {
|
||||
membership = new ConcurrentHashSet<>()
|
||||
memberships.put(p, membership)
|
||||
}
|
||||
membership.add(room)
|
||||
}
|
||||
|
||||
private void leaveRoom(Persona p, String room) {
|
||||
Set<Persona> existing = rooms.get(room)
|
||||
if (existing == null) {
|
||||
log.warning(p.getHumanReadableName() + " leaving room they hadn't joined")
|
||||
return
|
||||
}
|
||||
existing.remove(p)
|
||||
if (existing.isEmpty())
|
||||
rooms.remove(room)
|
||||
|
||||
Set<String> membership = memberships.get(p)
|
||||
if (membership == null) {
|
||||
log.warning(p.getHumanReadableName() + " didn't have any memberships")
|
||||
return
|
||||
}
|
||||
membership.remove(room)
|
||||
if (membership.isEmpty())
|
||||
memberships.remove(p)
|
||||
}
|
||||
|
||||
void onChatMessageEvent(ChatMessageEvent e) {
|
||||
if (e.host != me)
|
||||
return
|
||||
|
||||
ChatCommand command
|
||||
try {
|
||||
command = new ChatCommand(e.payload)
|
||||
} catch (Exception badCommand) {
|
||||
log.log(Level.WARNING, "bad chat command",badCommand)
|
||||
return
|
||||
}
|
||||
|
||||
if ((command.action.console && e.room != CONSOLE) ||
|
||||
(!command.action.console && e.room == CONSOLE) ||
|
||||
!command.action.user)
|
||||
return
|
||||
|
||||
switch(command.action) {
|
||||
case ChatAction.JOIN : processJoin(command.payload, e); break
|
||||
case ChatAction.LEAVE : processLeave(e); break
|
||||
case ChatAction.SAY : processSay(e); break
|
||||
case ChatAction.LIST : processList(e.sender.destination); break
|
||||
case ChatAction.INFO : processInfo(e.sender.destination); break
|
||||
case ChatAction.HELP : processHelp(e.sender.destination); break
|
||||
}
|
||||
}
|
||||
|
||||
private void processJoin(String room, ChatMessageEvent e) {
|
||||
joinRoom(e.sender, room)
|
||||
rooms[room].each {
|
||||
if (it == e.sender)
|
||||
return
|
||||
connections[it.destination].sendChat(e)
|
||||
}
|
||||
String payload = rooms[room].stream().filter({it != e.sender}).map({it.toBase64()})
|
||||
.collect(Collectors.joining(","))
|
||||
if (payload.length() == 0) {
|
||||
return
|
||||
}
|
||||
payload = "/JOINED $payload"
|
||||
long now = System.currentTimeMillis()
|
||||
UUID uuid = UUID.randomUUID()
|
||||
byte [] sig = ChatConnection.sign(uuid, now, room, payload, me, me, spk)
|
||||
ChatMessageEvent echo = new ChatMessageEvent(
|
||||
uuid : uuid,
|
||||
payload : payload,
|
||||
sender : me,
|
||||
host : me,
|
||||
room : room,
|
||||
chatTime : now,
|
||||
sig : sig
|
||||
)
|
||||
connections[e.sender.destination].sendChat(echo)
|
||||
}
|
||||
|
||||
private void processLeave(ChatMessageEvent e) {
|
||||
leaveRoom(e.sender, e.room)
|
||||
rooms.getOrDefault(e.room, []).each {
|
||||
if (it == e.sender)
|
||||
return
|
||||
connections[it.destination].sendChat(e)
|
||||
}
|
||||
}
|
||||
|
||||
private void processSay(ChatMessageEvent e) {
|
||||
if (rooms.containsKey(e.room)) {
|
||||
// not a private message
|
||||
rooms[e.room].each {
|
||||
if (it == e.sender)
|
||||
return
|
||||
connections[it.destination].sendChat(e)
|
||||
}
|
||||
} else {
|
||||
Persona target = new Persona(new ByteArrayInputStream(Base64.decode(e.room)))
|
||||
connections[target.destination]?.sendChat(e)
|
||||
}
|
||||
}
|
||||
|
||||
private void processList(Destination d) {
|
||||
String roomList = rooms.keySet().stream().filter({it != CONSOLE}).collect(Collectors.joining("\n"))
|
||||
roomList = "/SAY \nRoom List:\n"+roomList
|
||||
echo(roomList, d)
|
||||
}
|
||||
|
||||
private void processInfo(Destination d) {
|
||||
String info = "/SAY \nThe address of this server is\n========\n${me.toBase64()}\n========\nCopy/paste the above and share it\n"
|
||||
String connectedUsers = memberships.keySet().stream().map({it.getHumanReadableName()}).collect(Collectors.joining("\n"))
|
||||
info = "${info}\nConnected Users:\n$connectedUsers\n======="
|
||||
echo(info, d)
|
||||
}
|
||||
|
||||
private void processHelp(Destination d) {
|
||||
String help = """/SAY
|
||||
Available commands: /JOIN /LEAVE /SAY /LIST /INFO /HELP
|
||||
/JOIN <room name> - joins a room, or creates one if it does not exist. You must type this in the console
|
||||
/LEAVE - leaves a room. You must type this in the room you want to leave
|
||||
/SAY - optional, says something in the room you're in
|
||||
/LIST - lists the existing rooms on this server. You must type this in the console
|
||||
/INFO - shows information about this server. You must type this in the console
|
||||
/HELP - prints this help message
|
||||
"""
|
||||
echo(help, d)
|
||||
}
|
||||
|
||||
private void echo(String payload, Destination d) {
|
||||
log.info "echoing $payload"
|
||||
UUID uuid = UUID.randomUUID()
|
||||
long now = System.currentTimeMillis()
|
||||
byte [] sig = ChatConnection.sign(uuid, now, CONSOLE, payload, me, me, spk)
|
||||
ChatMessageEvent echo = new ChatMessageEvent(
|
||||
uuid : uuid,
|
||||
payload : payload,
|
||||
sender : me,
|
||||
host : me,
|
||||
room : CONSOLE,
|
||||
chatTime : now,
|
||||
sig : sig
|
||||
)
|
||||
connections[d]?.sendChat(echo)
|
||||
}
|
||||
|
||||
void stop() {
|
||||
if (running.compareAndSet(true, false)) {
|
||||
connections.each { k, v ->
|
||||
v.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
package com.muwire.core.chat
|
||||
|
||||
import java.util.concurrent.BlockingQueue
|
||||
import java.util.concurrent.LinkedBlockingQueue
|
||||
|
||||
import com.muwire.core.Persona
|
||||
|
||||
import groovy.util.logging.Log
|
||||
|
||||
@Log
|
||||
class LocalChatLink implements ChatLink {
|
||||
|
||||
public static final LocalChatLink INSTANCE = new LocalChatLink()
|
||||
|
||||
private final BlockingQueue messages = new LinkedBlockingQueue()
|
||||
|
||||
private LocalChatLink() {}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendChat(ChatMessageEvent e) {
|
||||
messages.put(e)
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendLeave(Persona p) {
|
||||
messages.put(p)
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPing() {}
|
||||
|
||||
@Override
|
||||
public Object nextEvent() {
|
||||
messages.take()
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUp() {
|
||||
true
|
||||
}
|
||||
|
||||
public Persona getPersona() {
|
||||
null
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
package com.muwire.core.chat
|
||||
|
||||
import com.muwire.core.Event
|
||||
import com.muwire.core.Persona
|
||||
|
||||
class UIConnectChatEvent extends Event {
|
||||
Persona host
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
package com.muwire.core.chat
|
||||
|
||||
import com.muwire.core.Event
|
||||
import com.muwire.core.Persona
|
||||
|
||||
class UIDisconnectChatEvent extends Event {
|
||||
Persona host
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
package com.muwire.core.chat
|
||||
|
||||
import com.muwire.core.Event
|
||||
import com.muwire.core.Persona
|
||||
|
||||
class UserDisconnectedEvent extends Event {
|
||||
Persona user
|
||||
Persona host
|
||||
}
|
@@ -15,6 +15,7 @@ import com.muwire.core.EventBus
|
||||
import com.muwire.core.InfoHash
|
||||
import com.muwire.core.MuWireSettings
|
||||
import com.muwire.core.Persona
|
||||
import com.muwire.core.chat.ChatServer
|
||||
import com.muwire.core.filecert.Certificate
|
||||
import com.muwire.core.filecert.CertificateManager
|
||||
import com.muwire.core.files.FileManager
|
||||
@@ -50,6 +51,7 @@ class ConnectionAcceptor {
|
||||
final FileManager fileManager
|
||||
final ConnectionEstablisher establisher
|
||||
final CertificateManager certificateManager
|
||||
final ChatServer chatServer
|
||||
|
||||
final ExecutorService acceptorThread
|
||||
final ExecutorService handshakerThreads
|
||||
@@ -61,7 +63,8 @@ class ConnectionAcceptor {
|
||||
ConnectionAcceptor(EventBus eventBus, UltrapeerConnectionManager manager,
|
||||
MuWireSettings settings, I2PAcceptor acceptor, HostCache hostCache,
|
||||
TrustService trustService, SearchManager searchManager, UploadManager uploadManager,
|
||||
FileManager fileManager, ConnectionEstablisher establisher, CertificateManager certificateManager) {
|
||||
FileManager fileManager, ConnectionEstablisher establisher, CertificateManager certificateManager,
|
||||
ChatServer chatServer) {
|
||||
this.eventBus = eventBus
|
||||
this.manager = manager
|
||||
this.settings = settings
|
||||
@@ -73,6 +76,7 @@ class ConnectionAcceptor {
|
||||
this.uploadManager = uploadManager
|
||||
this.establisher = establisher
|
||||
this.certificateManager = certificateManager
|
||||
this.chatServer = chatServer
|
||||
|
||||
acceptorThread = Executors.newSingleThreadExecutor { r ->
|
||||
def rv = new Thread(r)
|
||||
@@ -154,6 +158,9 @@ class ConnectionAcceptor {
|
||||
case (byte)'C':
|
||||
processCERTIFICATES(e)
|
||||
break
|
||||
case (byte)'I':
|
||||
processIRC(e)
|
||||
break
|
||||
default:
|
||||
throw new Exception("Invalid read $read")
|
||||
}
|
||||
@@ -299,6 +306,10 @@ class ConnectionAcceptor {
|
||||
throw new IOException("No Sender header")
|
||||
if (!headers.containsKey("Count"))
|
||||
throw new IOException("No Count header")
|
||||
|
||||
boolean chat = false
|
||||
if (headers.containsKey('Chat'))
|
||||
chat = Boolean.parseBoolean(headers['Chat'])
|
||||
|
||||
byte [] personaBytes = Base64.decode(headers['Sender'])
|
||||
Persona sender = new Persona(new ByteArrayInputStream(personaBytes))
|
||||
@@ -317,6 +328,7 @@ class ConnectionAcceptor {
|
||||
dis.readFully(payload)
|
||||
def json = slurper.parse(payload)
|
||||
results[i] = ResultsParser.parse(sender, resultsUUID, json)
|
||||
results[i].chat = chat
|
||||
}
|
||||
eventBus.publish(new UIResultBatchEvent(uuid: resultsUUID, results: results))
|
||||
} catch (IOException bad) {
|
||||
@@ -498,5 +510,14 @@ class ConnectionAcceptor {
|
||||
e.close()
|
||||
}
|
||||
}
|
||||
|
||||
private void processIRC(Endpoint e) {
|
||||
byte[] IRC = new byte[4]
|
||||
DataInputStream dis = new DataInputStream(e.getInputStream())
|
||||
dis.readFully(IRC)
|
||||
if (IRC != "RC\r\n".getBytes(StandardCharsets.US_ASCII))
|
||||
throw new Exception("Invalid IRC connection")
|
||||
chatServer.handle(e)
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@ class FileTree {
|
||||
private final TreeNode root = new TreeNode()
|
||||
private final Map<File, TreeNode> fileToNode = new ConcurrentHashMap<>()
|
||||
|
||||
void add(File file) {
|
||||
synchronized void add(File file) {
|
||||
List<File> path = new ArrayList<>()
|
||||
path.add(file)
|
||||
while (file.getParentFile() != null) {
|
||||
@@ -31,7 +31,7 @@ class FileTree {
|
||||
}
|
||||
}
|
||||
|
||||
boolean remove(File file) {
|
||||
synchronized boolean remove(File file) {
|
||||
TreeNode node = fileToNode.remove(file)
|
||||
if (node == null) {
|
||||
return false
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package com.muwire.core.search
|
||||
|
||||
import com.muwire.core.SharedFile
|
||||
import com.muwire.core.chat.ChatServer
|
||||
import com.muwire.core.connection.Endpoint
|
||||
import com.muwire.core.connection.I2PConnector
|
||||
import com.muwire.core.filecert.CertificateManager
|
||||
@@ -48,13 +49,16 @@ class ResultsSender {
|
||||
private final EventBus eventBus
|
||||
private final MuWireSettings settings
|
||||
private final CertificateManager certificateManager
|
||||
private final ChatServer chatServer
|
||||
|
||||
ResultsSender(EventBus eventBus, I2PConnector connector, Persona me, MuWireSettings settings, CertificateManager certificateManager) {
|
||||
ResultsSender(EventBus eventBus, I2PConnector connector, Persona me, MuWireSettings settings,
|
||||
CertificateManager certificateManager, ChatServer chatServer) {
|
||||
this.connector = connector;
|
||||
this.eventBus = eventBus
|
||||
this.me = me
|
||||
this.settings = settings
|
||||
this.certificateManager = certificateManager
|
||||
this.chatServer = chatServer
|
||||
}
|
||||
|
||||
void sendResults(UUID uuid, SharedFile[] results, Destination target, boolean oobInfohash, boolean compressedResults) {
|
||||
@@ -80,9 +84,11 @@ class ResultsSender {
|
||||
infohash : it.getInfoHash(),
|
||||
pieceSize : pieceSize,
|
||||
uuid : uuid,
|
||||
browse : settings.browseFiles,
|
||||
sources : suggested,
|
||||
comment : comment,
|
||||
certificates : certificates
|
||||
certificates : certificates,
|
||||
chat : chatServer.running.get() && settings.advertiseChat
|
||||
)
|
||||
uiResultEvents << uiResultEvent
|
||||
}
|
||||
@@ -130,6 +136,8 @@ class ResultsSender {
|
||||
os.write("RESULTS $uuid\r\n".getBytes(StandardCharsets.US_ASCII))
|
||||
os.write("Sender: ${me.toBase64()}\r\n".getBytes(StandardCharsets.US_ASCII))
|
||||
os.write("Count: $results.length\r\n".getBytes(StandardCharsets.US_ASCII))
|
||||
boolean chat = chatServer.running.get() && settings.advertiseChat
|
||||
os.write("Chat: $chat\r\n".getBytes(StandardCharsets.US_ASCII))
|
||||
os.write("\r\n".getBytes(StandardCharsets.US_ASCII))
|
||||
DataOutputStream dos = new DataOutputStream(new GZIPOutputStream(os))
|
||||
results.each {
|
||||
|
@@ -17,6 +17,7 @@ class UIResultEvent extends Event {
|
||||
String comment
|
||||
boolean browse
|
||||
int certificates
|
||||
boolean chat
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
@@ -5,6 +5,8 @@ import net.i2p.crypto.SigType;
|
||||
public class Constants {
|
||||
public static final byte PERSONA_VERSION = (byte)1;
|
||||
public static final byte FILE_CERT_VERSION = (byte)2;
|
||||
public static final int CHAT_VERSION = 1;
|
||||
|
||||
public static final SigType SIG_TYPE = SigType.EdDSA_SHA512_Ed25519;
|
||||
|
||||
public static final int MAX_HEADER_SIZE = 0x1 << 14;
|
||||
|
@@ -1,5 +1,5 @@
|
||||
group = com.muwire
|
||||
version = 0.6.2
|
||||
version = 0.6.5
|
||||
i2pVersion = 0.9.43
|
||||
groovyVersion = 2.4.15
|
||||
slf4jVersion = 1.7.25
|
||||
|
@@ -9,7 +9,7 @@ buildscript {
|
||||
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.8.2'
|
||||
classpath 'nl.javadude.gradle.plugins:license-gradle-plugin:0.11.0'
|
||||
classpath 'org.gradle.api.plugins:gradle-izpack-plugin:0.2.3'
|
||||
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4'
|
||||
classpath 'com.github.jengelman.gradle.plugins:shadow:5.2.0'
|
||||
classpath 'com.github.cr0:gradle-macappbundle-plugin:3.1.0'
|
||||
classpath 'org.kordamp.gradle:stats-gradle-plugin:0.2.2'
|
||||
classpath 'com.github.ben-manes:gradle-versions-plugin:0.17.0'
|
||||
|
@@ -111,4 +111,14 @@ mvcGroups {
|
||||
view = "com.muwire.gui.DownloadPreviewView"
|
||||
controller = "com.muwire.gui.DownloadPreviewController"
|
||||
}
|
||||
'chat-server' {
|
||||
model = 'com.muwire.gui.ChatServerModel'
|
||||
view = 'com.muwire.gui.ChatServerView'
|
||||
controller = 'com.muwire.gui.ChatServerController'
|
||||
}
|
||||
'chat-room' {
|
||||
model = 'com.muwire.gui.ChatRoomModel'
|
||||
view = 'com.muwire.gui.ChatRoomView'
|
||||
controller = 'com.muwire.gui.ChatRoomController'
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,270 @@
|
||||
package com.muwire.gui
|
||||
|
||||
import griffon.core.artifact.GriffonController
|
||||
import griffon.core.controller.ControllerAction
|
||||
import griffon.inject.MVCMember
|
||||
import griffon.metadata.ArtifactProviderFor
|
||||
import groovy.util.logging.Log
|
||||
import net.i2p.crypto.DSAEngine
|
||||
import net.i2p.data.Base64
|
||||
import net.i2p.data.DataHelper
|
||||
import net.i2p.data.Signature
|
||||
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.util.logging.Level
|
||||
|
||||
import javax.annotation.Nonnull
|
||||
import javax.swing.JOptionPane
|
||||
|
||||
import com.muwire.core.Persona
|
||||
import com.muwire.core.chat.ChatCommand
|
||||
import com.muwire.core.chat.ChatAction
|
||||
import com.muwire.core.chat.ChatConnection
|
||||
import com.muwire.core.chat.ChatMessageEvent
|
||||
import com.muwire.core.chat.ChatServer
|
||||
import com.muwire.core.trust.TrustEvent
|
||||
import com.muwire.core.trust.TrustLevel
|
||||
|
||||
@Log
|
||||
@ArtifactProviderFor(GriffonController)
|
||||
class ChatRoomController {
|
||||
@MVCMember @Nonnull
|
||||
ChatRoomModel model
|
||||
@MVCMember @Nonnull
|
||||
ChatRoomView view
|
||||
|
||||
boolean leftRoom
|
||||
|
||||
@ControllerAction
|
||||
void say() {
|
||||
String words = view.sayField.text
|
||||
view.sayField.setText(null)
|
||||
|
||||
ChatCommand command
|
||||
try {
|
||||
command = new ChatCommand(words)
|
||||
} catch (Exception nope) {
|
||||
command = new ChatCommand("/SAY $words")
|
||||
}
|
||||
|
||||
if (!command.action.user) {
|
||||
JOptionPane.showMessageDialog(null, "$words is not a user command","Invalid Command", JOptionPane.ERROR_MESSAGE)
|
||||
return
|
||||
}
|
||||
long now = System.currentTimeMillis()
|
||||
|
||||
if (command.action == ChatAction.SAY && command.payload.length() > 0) {
|
||||
String toShow = DataHelper.formatTime(now) + " <" + model.core.me.getHumanReadableName() + "> "+command.payload
|
||||
|
||||
view.roomTextArea.append(toShow)
|
||||
view.roomTextArea.append('\n')
|
||||
trimLines()
|
||||
}
|
||||
|
||||
if (command.action == ChatAction.JOIN) {
|
||||
String newRoom = command.payload
|
||||
if (!mvcGroup.parentGroup.childrenGroups.containsKey(newRoom)) {
|
||||
def params = [:]
|
||||
params['core'] = model.core
|
||||
params['tabName'] = model.host.getHumanReadableName() + "-chat-rooms"
|
||||
params['room'] = newRoom
|
||||
params['console'] = false
|
||||
params['host'] = model.host
|
||||
params['roomTabName'] = newRoom
|
||||
|
||||
mvcGroup.parentGroup.createMVCGroup("chat-room", model.host.getHumanReadableName()+"-"+newRoom, params)
|
||||
}
|
||||
}
|
||||
if (command.action == ChatAction.LEAVE && !model.console) {
|
||||
leftRoom = true
|
||||
view.closeTab.call()
|
||||
}
|
||||
|
||||
String room = model.console ? ChatServer.CONSOLE : model.room
|
||||
|
||||
UUID uuid = UUID.randomUUID()
|
||||
byte [] sig = ChatConnection.sign(uuid, now, room, command.source, model.core.me, model.host, model.core.spk)
|
||||
|
||||
def event = new ChatMessageEvent(uuid : uuid,
|
||||
payload : command.source,
|
||||
sender : model.core.me,
|
||||
host : model.host,
|
||||
room : room,
|
||||
chatTime : now,
|
||||
sig : sig)
|
||||
|
||||
model.core.eventBus.publish(event)
|
||||
}
|
||||
|
||||
@ControllerAction
|
||||
void privateMessage() {
|
||||
Persona p = view.getSelectedPersona()
|
||||
if (p == null)
|
||||
return
|
||||
String groupId = model.host.getHumanReadableName() + "-" + p.getHumanReadableName() +"-private-chat"
|
||||
if (p != model.core.me && !mvcGroup.parentGroup.childrenGroups.containsKey(groupId)) {
|
||||
def params = [:]
|
||||
params['core'] = model.core
|
||||
params['tabName'] = model.tabName
|
||||
params['room'] = p.toBase64()
|
||||
params['privateChat'] = true
|
||||
params['host'] = model.host
|
||||
params['roomTabName'] = p.getHumanReadableName()
|
||||
|
||||
mvcGroup.parentGroup.createMVCGroup("chat-room", groupId, params)
|
||||
}
|
||||
}
|
||||
|
||||
void markTrusted() {
|
||||
Persona p = view.getSelectedPersona()
|
||||
if (p == null)
|
||||
return
|
||||
String reason = JOptionPane.showInputDialog("Enter reason (optional)")
|
||||
model.core.eventBus.publish(new TrustEvent(persona : p, level : TrustLevel.TRUSTED, reason : reason))
|
||||
view.refreshMembersTable()
|
||||
}
|
||||
|
||||
void markDistrusted() {
|
||||
Persona p = view.getSelectedPersona()
|
||||
if (p == null)
|
||||
return
|
||||
String reason = JOptionPane.showInputDialog("Enter reason (optional)")
|
||||
model.core.eventBus.publish(new TrustEvent(persona : p, level : TrustLevel.DISTRUSTED, reason : reason))
|
||||
view.refreshMembersTable()
|
||||
}
|
||||
|
||||
void markNeutral() {
|
||||
Persona p = view.getSelectedPersona()
|
||||
if (p == null)
|
||||
return
|
||||
model.core.eventBus.publish(new TrustEvent(persona : p, level : TrustLevel.NEUTRAL))
|
||||
view.refreshMembersTable()
|
||||
}
|
||||
|
||||
void browse() {
|
||||
Persona p = view.getSelectedPersona()
|
||||
if (p == null)
|
||||
return
|
||||
String groupId = p.getHumanReadableName() + "-browse"
|
||||
def params = [:]
|
||||
params['host'] = p
|
||||
params['core'] = model.core
|
||||
mvcGroup.createMVCGroup("browse",groupId,params)
|
||||
}
|
||||
|
||||
void leaveRoom() {
|
||||
if (leftRoom)
|
||||
return
|
||||
leftRoom = true
|
||||
long now = System.currentTimeMillis()
|
||||
UUID uuid = UUID.randomUUID()
|
||||
byte [] sig = ChatConnection.sign(uuid, now, model.room, "/LEAVE", model.core.me, model.host, model.core.spk)
|
||||
def event = new ChatMessageEvent(uuid : uuid,
|
||||
payload : "/LEAVE",
|
||||
sender : model.core.me,
|
||||
host : model.host,
|
||||
room : model.room,
|
||||
chatTime : now,
|
||||
sig : sig)
|
||||
model.core.eventBus.publish(event)
|
||||
}
|
||||
|
||||
void handleChatMessage(ChatMessageEvent e) {
|
||||
ChatCommand command
|
||||
try {
|
||||
command = new ChatCommand(e.payload)
|
||||
} catch (Exception bad) {
|
||||
log.log(Level.WARNING,"bad chat command",bad)
|
||||
return
|
||||
}
|
||||
log.info("$model.room processing $command.action")
|
||||
switch(command.action) {
|
||||
case ChatAction.SAY : processSay(e, command.payload);break
|
||||
case ChatAction.JOIN : processJoin(e.timestamp, e.sender); break
|
||||
case ChatAction.JOINED : processJoined(command.payload); break
|
||||
case ChatAction.LEAVE : processLeave(e.timestamp, e.sender); break
|
||||
}
|
||||
}
|
||||
|
||||
private void processSay(ChatMessageEvent e, String text) {
|
||||
String toDisplay = DataHelper.formatTime(e.timestamp) + " <"+e.sender.getHumanReadableName()+"> " + text + "\n"
|
||||
runInsideUIAsync {
|
||||
view.roomTextArea.append(toDisplay)
|
||||
trimLines()
|
||||
}
|
||||
}
|
||||
|
||||
private void processJoin(long timestamp, Persona p) {
|
||||
String toDisplay = DataHelper.formatTime(timestamp) + " " + p.getHumanReadableName() + " joined the room\n"
|
||||
runInsideUIAsync {
|
||||
model.members.add(p)
|
||||
view.roomTextArea.append(toDisplay)
|
||||
trimLines()
|
||||
view.membersTable?.model?.fireTableDataChanged()
|
||||
}
|
||||
}
|
||||
|
||||
private void processJoined(String list) {
|
||||
runInsideUIAsync {
|
||||
list.split(",").each {
|
||||
Persona p = new Persona(new ByteArrayInputStream(Base64.decode(it)))
|
||||
model.members.add(p)
|
||||
}
|
||||
view.membersTable?.model?.fireTableDataChanged()
|
||||
}
|
||||
}
|
||||
|
||||
private void processLeave(long timestamp, Persona p) {
|
||||
String toDisplay = DataHelper.formatTime(timestamp) + " " + p.getHumanReadableName() + " left the room\n"
|
||||
runInsideUIAsync {
|
||||
model.members.remove(p)
|
||||
view.roomTextArea.append(toDisplay)
|
||||
trimLines()
|
||||
view.membersTable?.model?.fireTableDataChanged()
|
||||
}
|
||||
}
|
||||
|
||||
void handleLeave(Persona p) {
|
||||
String toDisplay = DataHelper.formatTime(System.currentTimeMillis()) + " " + p.getHumanReadableName() + " disconnected\n"
|
||||
runInsideUIAsync {
|
||||
if (model.members.remove(p)) {
|
||||
view.roomTextArea.append(toDisplay)
|
||||
trimLines()
|
||||
view.membersTable?.model?.fireTableDataChanged()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void trimLines() {
|
||||
if (model.settings.maxChatLines < 0)
|
||||
return
|
||||
while(view.roomTextArea.getLineCount() > model.settings.maxChatLines) {
|
||||
int line0Start = view.roomTextArea.getLineStartOffset(0)
|
||||
int line0End = view.roomTextArea.getLineEndOffset(0)
|
||||
view.roomTextArea.replaceRange(null, line0Start, line0End)
|
||||
}
|
||||
}
|
||||
|
||||
void rejoinRoom() {
|
||||
if (model.room == "Console")
|
||||
return
|
||||
|
||||
model.members.clear()
|
||||
model.members.add(model.core.me)
|
||||
|
||||
UUID uuid = UUID.randomUUID()
|
||||
long now = System.currentTimeMillis()
|
||||
String join = "/JOIN $model.room"
|
||||
byte [] sig = ChatConnection.sign(uuid, now, ChatServer.CONSOLE, join, model.core.me, model.host, model.core.spk)
|
||||
def event = new ChatMessageEvent(
|
||||
uuid : uuid,
|
||||
payload : join,
|
||||
sender : model.core.me,
|
||||
host : model.host,
|
||||
room : ChatServer.CONSOLE,
|
||||
chatTime : now,
|
||||
sig : sig
|
||||
)
|
||||
model.core.eventBus.publish(event)
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
package com.muwire.gui
|
||||
|
||||
import griffon.core.artifact.GriffonController
|
||||
import griffon.core.controller.ControllerAction
|
||||
import griffon.inject.MVCMember
|
||||
import griffon.metadata.ArtifactProviderFor
|
||||
import javax.annotation.Nonnull
|
||||
|
||||
import com.muwire.core.chat.UIDisconnectChatEvent
|
||||
|
||||
@ArtifactProviderFor(GriffonController)
|
||||
class ChatServerController {
|
||||
@MVCMember @Nonnull
|
||||
ChatServerModel model
|
||||
|
||||
@ControllerAction
|
||||
void disconnect() {
|
||||
switch(model.buttonText) {
|
||||
case "Disconnect" :
|
||||
model.buttonText = "Connect"
|
||||
model.core.eventBus.publish(new UIDisconnectChatEvent(host : model.host))
|
||||
break
|
||||
case "Connect" :
|
||||
model.connect()
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
@@ -234,8 +234,11 @@ class MainFrameController {
|
||||
int row = view.getSelectedTrustTablesRow(tableName)
|
||||
if (row < 0)
|
||||
return
|
||||
String reason = null
|
||||
if (level != TrustLevel.NEUTRAL)
|
||||
reason = JOptionPane.showInputDialog("Enter reason (optional)")
|
||||
builder.getVariable(tableName).model.fireTableDataChanged()
|
||||
core.eventBus.publish(new TrustEvent(persona : list[row].persona, level : level))
|
||||
core.eventBus.publish(new TrustEvent(persona : list[row].persona, level : level, reason : reason))
|
||||
}
|
||||
|
||||
@ControllerAction
|
||||
@@ -322,6 +325,31 @@ class MainFrameController {
|
||||
return null
|
||||
model.subscriptions[row]
|
||||
}
|
||||
|
||||
@ControllerAction
|
||||
void browseFromTrusted() {
|
||||
int row = view.getSelectedTrustTablesRow("trusted-table")
|
||||
if (row < 0)
|
||||
return
|
||||
Persona p = model.trusted[row].persona
|
||||
|
||||
String groupId = p.getHumanReadableName() + "-browse"
|
||||
def params = [:]
|
||||
params['host'] = p
|
||||
params['core'] = model.core
|
||||
mvcGroup.createMVCGroup("browse",groupId,params)
|
||||
}
|
||||
|
||||
@ControllerAction
|
||||
void chatFromTrusted() {
|
||||
int row = view.getSelectedTrustTablesRow("trusted-table")
|
||||
if (row < 0)
|
||||
return
|
||||
Persona p = model.trusted[row].persona
|
||||
|
||||
startChat(p)
|
||||
view.showChatWindow.call()
|
||||
}
|
||||
|
||||
void unshareSelectedFile() {
|
||||
def sf = view.selectedSharedFiles()
|
||||
@@ -420,6 +448,51 @@ class MainFrameController {
|
||||
Desktop.getDesktop().open(selected[0].file.getParentFile())
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
|
||||
@ControllerAction
|
||||
void startChatServer() {
|
||||
model.core.chatServer.start()
|
||||
model.chatServerRunning = true
|
||||
|
||||
if (!mvcGroup.getChildrenGroups().containsKey("local-chat-server")) {
|
||||
def params = [:]
|
||||
params['core'] = model.core
|
||||
params['host'] = model.core.me
|
||||
mvcGroup.createMVCGroup("chat-server","local-chat-server", params)
|
||||
}
|
||||
}
|
||||
|
||||
@ControllerAction
|
||||
void stopChatServer() {
|
||||
model.core.chatServer.stop()
|
||||
model.chatServerRunning = false
|
||||
}
|
||||
|
||||
@ControllerAction
|
||||
void connectChatServer() {
|
||||
String address = JOptionPane.showInputDialog("Copy/paste the address of the server here")
|
||||
if (address == null)
|
||||
return
|
||||
Persona p
|
||||
try {
|
||||
p = new Persona(new ByteArrayInputStream(Base64.decode(address)))
|
||||
} catch (Exception bad) {
|
||||
JOptionPane.showMessageDialog(null, "Invalid server address", "Invalid server address", JOptionPane.ERROR_MESSAGE)
|
||||
return
|
||||
}
|
||||
|
||||
startChat(p)
|
||||
}
|
||||
|
||||
void startChat(Persona p) {
|
||||
if (!mvcGroup.getChildrenGroups().containsKey(p.getHumanReadableName())) {
|
||||
def params = [:]
|
||||
params['core'] = model.core
|
||||
params['host'] = p
|
||||
mvcGroup.createMVCGroup("chat-server", p.getHumanReadableName(), params)
|
||||
} else
|
||||
mvcGroup.getChildrenGroups().get(p.getHumanReadableName()).model.connect()
|
||||
}
|
||||
|
||||
void saveMuWireSettings() {
|
||||
core.saveMuSettings()
|
||||
|
@@ -139,6 +139,22 @@ class OptionsController {
|
||||
String trustListInterval = view.trustListIntervalField.text
|
||||
model.trustListInterval = trustListInterval
|
||||
settings.trustListInterval = Integer.parseInt(trustListInterval)
|
||||
|
||||
boolean startChatServer = view.startChatServerCheckbox.model.isSelected()
|
||||
model.startChatServer = startChatServer
|
||||
settings.startChatServer = startChatServer
|
||||
|
||||
String maxChatConnections = view.maxChatConnectionsField.text
|
||||
model.maxChatConnections = Integer.parseInt(maxChatConnections)
|
||||
settings.maxChatConnections = Integer.parseInt(maxChatConnections)
|
||||
|
||||
boolean advertiseChat = view.advertiseChatCheckbox.model.isSelected()
|
||||
model.advertiseChat = advertiseChat
|
||||
settings.advertiseChat = advertiseChat
|
||||
|
||||
int maxChatLines = Integer.parseInt(view.maxChatLinesField.text)
|
||||
model.maxChatLines = maxChatLines
|
||||
uiSettings.maxChatLines = maxChatLines
|
||||
|
||||
core.saveMuSettings()
|
||||
|
||||
|
@@ -99,13 +99,24 @@ class SearchTabController {
|
||||
if (sender == null)
|
||||
return
|
||||
|
||||
String groupId = sender.getHumanReadableName()
|
||||
String groupId = sender.getHumanReadableName() + "-browse"
|
||||
Map<String,Object> params = new HashMap<>()
|
||||
params['host'] = sender
|
||||
params['core'] = core
|
||||
|
||||
mvcGroup.createMVCGroup("browse", groupId, params)
|
||||
}
|
||||
|
||||
@ControllerAction
|
||||
void chat() {
|
||||
def sender = view.selectedSender()
|
||||
if (sender == null)
|
||||
return
|
||||
|
||||
def parent = mvcGroup.parentGroup
|
||||
parent.controller.startChat(sender)
|
||||
parent.view.showChatWindow.call()
|
||||
}
|
||||
|
||||
@ControllerAction
|
||||
void showComment() {
|
||||
|
28
gui/griffon-app/models/com/muwire/gui/ChatRoomModel.groovy
Normal file
28
gui/griffon-app/models/com/muwire/gui/ChatRoomModel.groovy
Normal file
@@ -0,0 +1,28 @@
|
||||
package com.muwire.gui
|
||||
|
||||
import com.muwire.core.Core
|
||||
import com.muwire.core.Persona
|
||||
|
||||
import griffon.core.artifact.GriffonModel
|
||||
import griffon.transform.Observable
|
||||
import griffon.metadata.ArtifactProviderFor
|
||||
|
||||
@ArtifactProviderFor(GriffonModel)
|
||||
class ChatRoomModel {
|
||||
Core core
|
||||
Persona host
|
||||
String tabName
|
||||
String room
|
||||
boolean console
|
||||
boolean privateChat
|
||||
String roomTabName
|
||||
|
||||
def members = []
|
||||
|
||||
UISettings settings
|
||||
|
||||
void mvcGroupInit(Map<String,String> args) {
|
||||
members.add(core.me)
|
||||
settings = application.context.get("ui-settings")
|
||||
}
|
||||
}
|
148
gui/griffon-app/models/com/muwire/gui/ChatServerModel.groovy
Normal file
148
gui/griffon-app/models/com/muwire/gui/ChatServerModel.groovy
Normal file
@@ -0,0 +1,148 @@
|
||||
package com.muwire.gui
|
||||
|
||||
import java.util.logging.Level
|
||||
|
||||
import com.muwire.core.Core
|
||||
import com.muwire.core.Persona
|
||||
import com.muwire.core.chat.ChatCommand
|
||||
import com.muwire.core.chat.ChatAction
|
||||
import com.muwire.core.chat.ChatConnectionAttemptStatus
|
||||
import com.muwire.core.chat.ChatConnectionEvent
|
||||
import com.muwire.core.chat.ChatLink
|
||||
import com.muwire.core.chat.ChatMessageEvent
|
||||
import com.muwire.core.chat.UIConnectChatEvent
|
||||
|
||||
import griffon.core.artifact.GriffonModel
|
||||
import griffon.transform.Observable
|
||||
import groovy.util.logging.Log
|
||||
import griffon.metadata.ArtifactProviderFor
|
||||
|
||||
@Log
|
||||
@ArtifactProviderFor(GriffonModel)
|
||||
class ChatServerModel {
|
||||
Persona host
|
||||
Core core
|
||||
|
||||
@Observable boolean disconnectActionEnabled
|
||||
@Observable String buttonText = "Disconnect"
|
||||
@Observable ChatConnectionAttemptStatus status
|
||||
|
||||
volatile ChatLink link
|
||||
volatile Thread poller
|
||||
volatile boolean running
|
||||
|
||||
void mvcGroupInit(Map<String, String> params) {
|
||||
disconnectActionEnabled = host != core.me // can't disconnect from myself
|
||||
core.eventBus.register(ChatConnectionEvent.class, this)
|
||||
|
||||
connect()
|
||||
}
|
||||
|
||||
void connect() {
|
||||
runInsideUIAsync {
|
||||
buttonText = "Disconnect"
|
||||
}
|
||||
core.eventBus.publish(new UIConnectChatEvent(host : host))
|
||||
}
|
||||
|
||||
void mvcGroupDestroy() {
|
||||
stopPoller()
|
||||
core.eventBus.unregister(ChatConnectionEvent.class, this)
|
||||
}
|
||||
|
||||
private void startPoller() {
|
||||
if (running)
|
||||
return
|
||||
running = true
|
||||
poller = new Thread({eventLoop()} as Runnable)
|
||||
poller.setDaemon(true)
|
||||
poller.start()
|
||||
}
|
||||
|
||||
private void stopPoller() {
|
||||
running = false
|
||||
poller?.interrupt()
|
||||
link = null
|
||||
}
|
||||
|
||||
void onChatConnectionEvent(ChatConnectionEvent e) {
|
||||
if (e.persona != host)
|
||||
return
|
||||
|
||||
runInsideUIAsync {
|
||||
status = e.status
|
||||
}
|
||||
|
||||
if (e.status == ChatConnectionAttemptStatus.SUCCESSFUL) {
|
||||
ChatLink link = e.connection
|
||||
if (link == null)
|
||||
return
|
||||
this.link = e.connection
|
||||
|
||||
startPoller()
|
||||
|
||||
mvcGroup.childrenGroups.each {k,v ->
|
||||
v.controller.rejoinRoom()
|
||||
}
|
||||
} else {
|
||||
stopPoller()
|
||||
}
|
||||
}
|
||||
|
||||
private void eventLoop() {
|
||||
Thread.sleep(1000)
|
||||
while(running) {
|
||||
ChatLink link = this.link
|
||||
if (link == null || !link.isUp()) {
|
||||
Thread.sleep(100)
|
||||
continue
|
||||
}
|
||||
|
||||
Object event = link.nextEvent()
|
||||
if (event instanceof ChatMessageEvent)
|
||||
handleChatMessage(event)
|
||||
else if (event instanceof Persona)
|
||||
handleLeave(event)
|
||||
else
|
||||
throw new IllegalArgumentException("event type $event")
|
||||
}
|
||||
}
|
||||
|
||||
private void handleChatMessage(ChatMessageEvent e) {
|
||||
ChatCommand chatCommand
|
||||
try {
|
||||
chatCommand = new ChatCommand(e.payload)
|
||||
} catch (Exception badCommand) {
|
||||
log.log(Level.WARNING,"bad chat command",badCommand)
|
||||
return
|
||||
}
|
||||
String room = e.room
|
||||
if (chatCommand.action == ChatAction.JOIN) {
|
||||
room = chatCommand.payload
|
||||
}
|
||||
if (chatCommand.action == ChatAction.SAY &&
|
||||
room == core.me.toBase64()) {
|
||||
String groupId = host.getHumanReadableName()+"-"+e.sender.getHumanReadableName() + "-private-chat"
|
||||
if (!mvcGroup.childrenGroups.containsKey(groupId)) {
|
||||
def params = [:]
|
||||
params['core'] = core
|
||||
params['tabName'] = host.getHumanReadableName() + "-chat-rooms"
|
||||
params['room'] = e.sender.toBase64()
|
||||
params['privateChat'] = true
|
||||
params['host'] = host
|
||||
params['roomTabName'] = e.sender.getHumanReadableName()
|
||||
|
||||
mvcGroup.createMVCGroup("chat-room",groupId, params)
|
||||
}
|
||||
room = groupId
|
||||
} else
|
||||
room = host.getHumanReadableName()+"-"+room
|
||||
mvcGroup.childrenGroups[room]?.controller?.handleChatMessage(e)
|
||||
}
|
||||
|
||||
private void handleLeave(Persona p) {
|
||||
mvcGroup.childrenGroups.each { k, v ->
|
||||
v.controller.handleLeave(p)
|
||||
}
|
||||
}
|
||||
}
|
@@ -117,6 +117,9 @@ class MainFrameModel {
|
||||
@Observable boolean uploadsPaneButtonEnabled
|
||||
@Observable boolean monitorPaneButtonEnabled
|
||||
@Observable boolean trustPaneButtonEnabled
|
||||
@Observable boolean chatPaneButtonEnabled
|
||||
|
||||
@Observable boolean chatServerRunning
|
||||
|
||||
@Observable Downloader downloader
|
||||
|
||||
@@ -218,6 +221,8 @@ class MainFrameModel {
|
||||
core.eventBus.publish(new ContentControlEvent(term : it, regex: true, add: true))
|
||||
}
|
||||
|
||||
chatServerRunning = core.chatServer.running.get()
|
||||
|
||||
timer.schedule({
|
||||
if (core.shutdown.get())
|
||||
return
|
||||
@@ -252,6 +257,10 @@ class MainFrameModel {
|
||||
uploadsPaneButtonEnabled = true
|
||||
monitorPaneButtonEnabled = true
|
||||
trustPaneButtonEnabled = true
|
||||
chatPaneButtonEnabled = true
|
||||
|
||||
if (core.muOptions.startChatServer)
|
||||
controller.startChatServer()
|
||||
}
|
||||
})
|
||||
|
||||
|
@@ -56,6 +56,11 @@ class OptionsModel {
|
||||
@Observable boolean trustLists
|
||||
@Observable String trustListInterval
|
||||
|
||||
// chat options
|
||||
@Observable boolean startChatServer
|
||||
@Observable int maxChatConnections
|
||||
@Observable boolean advertiseChat
|
||||
@Observable int maxChatLines
|
||||
|
||||
void mvcGroupInit(Map<String, String> args) {
|
||||
MuWireSettings settings = application.context.get("muwire-settings")
|
||||
@@ -104,5 +109,10 @@ class OptionsModel {
|
||||
searchExtraHop = settings.searchExtraHop
|
||||
trustLists = settings.allowTrustLists
|
||||
trustListInterval = String.valueOf(settings.trustListInterval)
|
||||
|
||||
startChatServer = settings.startChatServer
|
||||
maxChatConnections = settings.maxChatConnections
|
||||
advertiseChat = settings.advertiseChat
|
||||
maxChatLines = uiSettings.maxChatLines
|
||||
}
|
||||
}
|
@@ -24,6 +24,7 @@ class SearchTabModel {
|
||||
@Observable boolean browseActionEnabled
|
||||
@Observable boolean viewCommentActionEnabled
|
||||
@Observable boolean viewCertificatesActionEnabled
|
||||
@Observable boolean chatActionEnabled
|
||||
@Observable boolean groupedByFile
|
||||
|
||||
Core core
|
||||
|
173
gui/griffon-app/views/com/muwire/gui/ChatRoomView.groovy
Normal file
173
gui/griffon-app/views/com/muwire/gui/ChatRoomView.groovy
Normal file
@@ -0,0 +1,173 @@
|
||||
package com.muwire.gui
|
||||
|
||||
import griffon.core.artifact.GriffonView
|
||||
import griffon.inject.MVCMember
|
||||
import griffon.metadata.ArtifactProviderFor
|
||||
|
||||
import javax.swing.JMenuItem
|
||||
import javax.swing.JPopupMenu
|
||||
import javax.swing.JSplitPane
|
||||
import javax.swing.ListSelectionModel
|
||||
import javax.swing.SwingConstants
|
||||
import javax.swing.SpringLayout.Constraints
|
||||
|
||||
import com.muwire.core.Persona
|
||||
|
||||
import java.awt.BorderLayout
|
||||
import java.awt.event.MouseAdapter
|
||||
import java.awt.event.MouseEvent
|
||||
|
||||
import javax.annotation.Nonnull
|
||||
|
||||
@ArtifactProviderFor(GriffonView)
|
||||
class ChatRoomView {
|
||||
@MVCMember @Nonnull
|
||||
FactoryBuilderSupport builder
|
||||
@MVCMember @Nonnull
|
||||
ChatRoomModel model
|
||||
@MVCMember @Nonnull
|
||||
ChatRoomController controller
|
||||
|
||||
def pane
|
||||
def parent
|
||||
def sayField
|
||||
def roomTextArea
|
||||
def membersTable
|
||||
def lastMembersTableSortEvent
|
||||
|
||||
void initUI() {
|
||||
int rowHeight = application.context.get("row-height")
|
||||
if (model.console || model.privateChat) {
|
||||
pane = builder.panel {
|
||||
borderLayout()
|
||||
panel(constraints : BorderLayout.CENTER) {
|
||||
gridLayout(rows : 1, cols : 1)
|
||||
scrollPane {
|
||||
roomTextArea = textArea(editable : false, lineWrap : true, wrapStyleWord : true)
|
||||
}
|
||||
}
|
||||
panel(constraints : BorderLayout.SOUTH) {
|
||||
borderLayout()
|
||||
label(text : "Say something here: ", constraints : BorderLayout.WEST)
|
||||
sayField = textField(actionPerformed : {controller.say()}, constraints : BorderLayout.CENTER)
|
||||
button(text : "Say", constraints : BorderLayout.EAST, sayAction)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
pane = builder.panel {
|
||||
borderLayout()
|
||||
panel(constraints : BorderLayout.CENTER) {
|
||||
gridLayout(rows : 1, cols : 1)
|
||||
splitPane(orientation : JSplitPane.HORIZONTAL_SPLIT, continuousLayout : true, dividerLocation : 300) {
|
||||
panel {
|
||||
gridLayout(rows : 1, cols : 1)
|
||||
scrollPane {
|
||||
membersTable = table(autoCreateRowSorter : true, rowHeight : rowHeight) {
|
||||
tableModel(list : model.members) {
|
||||
closureColumn(header : "Name", preferredWidth: 100, type: String, read : {it.getHumanReadableName()})
|
||||
closureColumn(header : "Trust Status", preferredWidth: 30, type : String, read : {String.valueOf(model.core.trustService.getLevel(it.destination))})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
panel {
|
||||
gridLayout(rows : 1, cols : 1)
|
||||
scrollPane {
|
||||
roomTextArea = textArea(editable : false, lineWrap : true, wrapStyleWord : true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
panel(constraints : BorderLayout.SOUTH) {
|
||||
borderLayout()
|
||||
label(text : "Say something here: ", constraints : BorderLayout.WEST)
|
||||
sayField = textField(actionPerformed : {controller.say()}, constraints : BorderLayout.CENTER)
|
||||
button(text : "Say", constraints : BorderLayout.EAST, sayAction)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void mvcGroupInit(Map<String,String> args) {
|
||||
parent = mvcGroup.parentGroup.view.builder.getVariable(model.tabName)
|
||||
parent.addTab(model.roomTabName, pane)
|
||||
|
||||
int index = parent.indexOfComponent(pane)
|
||||
parent.setSelectedIndex(index)
|
||||
|
||||
def tabPanel = builder.panel {
|
||||
borderLayout()
|
||||
panel (constraints : BorderLayout.CENTER) {
|
||||
label(text : model.roomTabName)
|
||||
}
|
||||
button(icon : imageIcon("/close_tab.png"), preferredSize: [20, 20], constraints : BorderLayout.EAST,
|
||||
actionPerformed : closeTab )
|
||||
}
|
||||
if (!model.console)
|
||||
parent.setTabComponentAt(index, tabPanel)
|
||||
|
||||
if (membersTable != null) {
|
||||
|
||||
membersTable.rowSorter.addRowSorterListener({evt -> lastMembersTableSortEvent = evt})
|
||||
membersTable.rowSorter.setSortsOnUpdates(true)
|
||||
membersTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION)
|
||||
|
||||
membersTable.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if (e.button == MouseEvent.BUTTON1 && e.clickCount > 1) {
|
||||
controller.privateMessage()
|
||||
} else if (e.isPopupTrigger() || e.button == MouseEvent.BUTTON3)
|
||||
showPopupMenu(e)
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (e.isPopupTrigger() || e.button == MouseEvent.BUTTON3)
|
||||
showPopupMenu(e)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private void showPopupMenu(MouseEvent e) {
|
||||
JPopupMenu menu = new JPopupMenu()
|
||||
JMenuItem privateChat = new JMenuItem("Start Private Chat")
|
||||
privateChat.addActionListener({controller.privateMessage()})
|
||||
menu.add(privateChat)
|
||||
JMenuItem browse = new JMenuItem("Browse")
|
||||
browse.addActionListener({controller.browse()})
|
||||
menu.add(browse)
|
||||
JMenuItem markTrusted = new JMenuItem("Mark Trusted")
|
||||
markTrusted.addActionListener({controller.markTrusted()})
|
||||
menu.add(markTrusted)
|
||||
JMenuItem markNeutral = new JMenuItem("Mark Neutral")
|
||||
markNeutral.addActionListener({controller.markNeutral()})
|
||||
menu.add(markNeutral)
|
||||
JMenuItem markDistrusted = new JMenuItem("Mark Distrusted")
|
||||
markDistrusted.addActionListener({controller.markDistrusted()})
|
||||
menu.add(markDistrusted)
|
||||
menu.show(e.getComponent(), e.getX(), e.getY())
|
||||
}
|
||||
|
||||
Persona getSelectedPersona() {
|
||||
int selectedRow = membersTable.getSelectedRow()
|
||||
if (selectedRow < 0)
|
||||
return null
|
||||
if (lastMembersTableSortEvent != null)
|
||||
selectedRow = membersTable.rowSorter.convertRowIndexToModel(selectedRow)
|
||||
model.members[selectedRow]
|
||||
}
|
||||
|
||||
void refreshMembersTable() {
|
||||
int selectedRow = membersTable.getSelectedRow()
|
||||
membersTable.model.fireTableDataChanged()
|
||||
membersTable.selectionModel.setSelectionInterval(selectedRow, selectedRow)
|
||||
}
|
||||
|
||||
def closeTab = {
|
||||
int index = parent.indexOfComponent(pane)
|
||||
parent.removeTabAt(index)
|
||||
controller.leaveRoom()
|
||||
mvcGroup.destroy()
|
||||
}
|
||||
}
|
81
gui/griffon-app/views/com/muwire/gui/ChatServerView.groovy
Normal file
81
gui/griffon-app/views/com/muwire/gui/ChatServerView.groovy
Normal file
@@ -0,0 +1,81 @@
|
||||
package com.muwire.gui
|
||||
|
||||
import griffon.core.artifact.GriffonView
|
||||
import griffon.inject.MVCMember
|
||||
import griffon.metadata.ArtifactProviderFor
|
||||
import javax.swing.SwingConstants
|
||||
|
||||
import com.muwire.core.chat.ChatServer
|
||||
|
||||
import java.awt.BorderLayout
|
||||
|
||||
import javax.annotation.Nonnull
|
||||
|
||||
@ArtifactProviderFor(GriffonView)
|
||||
class ChatServerView {
|
||||
@MVCMember @Nonnull
|
||||
FactoryBuilderSupport builder
|
||||
@MVCMember @Nonnull
|
||||
ChatServerModel model
|
||||
@MVCMember @Nonnull
|
||||
ChatServerController controller
|
||||
|
||||
def pane
|
||||
def parent
|
||||
|
||||
void initUI() {
|
||||
pane = builder.panel {
|
||||
borderLayout()
|
||||
tabbedPane(id : model.host.getHumanReadableName()+"-chat-rooms", constraints : BorderLayout.CENTER)
|
||||
panel(constraints : BorderLayout.SOUTH) {
|
||||
gridLayout(rows : 1, cols : 3)
|
||||
panel {}
|
||||
panel {
|
||||
button(text : bind {model.buttonText}, enabled : bind {model.disconnectActionEnabled}, disconnectAction)
|
||||
}
|
||||
panel {
|
||||
label(text : "Connection Status ")
|
||||
label(text : bind {model.status.toString()})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void mvcGroupInit(Map<String,String> args) {
|
||||
parent = mvcGroup.parentGroup.view.builder.getVariable("chat-tabs")
|
||||
parent.addTab(model.host.getHumanReadableName(), pane)
|
||||
|
||||
int index = parent.indexOfComponent(pane)
|
||||
parent.setSelectedIndex(index)
|
||||
|
||||
def tabPanel
|
||||
builder.with {
|
||||
tabPanel = panel {
|
||||
borderLayout()
|
||||
panel (constraints : BorderLayout.CENTER) {
|
||||
String text = model.host == model.core.me ? "Local Server" : model.host.getHumanReadableName()
|
||||
label(text : text)
|
||||
}
|
||||
button(icon : imageIcon("/close_tab.png"), preferredSize: [20, 20], constraints : BorderLayout.EAST,
|
||||
actionPerformed : closeTab )
|
||||
}
|
||||
}
|
||||
parent.setTabComponentAt(index, tabPanel)
|
||||
|
||||
def params = [:]
|
||||
params['core'] = model.core
|
||||
params['tabName'] = model.host.getHumanReadableName() + "-chat-rooms"
|
||||
params['room'] = 'Console'
|
||||
params['roomTabName'] = 'Console'
|
||||
params['console'] = true
|
||||
params['host'] = model.host
|
||||
mvcGroup.createMVCGroup("chat-room",model.host.getHumanReadableName()+"-"+ChatServer.CONSOLE, params)
|
||||
}
|
||||
|
||||
def closeTab = {
|
||||
controller.disconnect()
|
||||
int index = parent.indexOfComponent(pane)
|
||||
parent.removeTabAt(index)
|
||||
mvcGroup.destroy()
|
||||
}
|
||||
}
|
@@ -142,6 +142,7 @@ class MainFrameView {
|
||||
if (settings.showMonitor)
|
||||
button(text: "Monitor", enabled: bind{model.monitorPaneButtonEnabled},actionPerformed : showMonitorWindow)
|
||||
button(text: "Trust", enabled:bind{model.trustPaneButtonEnabled},actionPerformed : showTrustWindow)
|
||||
button(text: "Chat", enabled : bind{model.chatPaneButtonEnabled}, actionPerformed : showChatWindow)
|
||||
}
|
||||
panel(id: "top-panel", constraints: BorderLayout.CENTER) {
|
||||
cardLayout()
|
||||
@@ -305,7 +306,7 @@ class MainFrameView {
|
||||
radioButton(text : "Table", selected : false, buttonGroup : sharedViewType, actionPerformed : showSharedFilesTable)
|
||||
}
|
||||
panel {
|
||||
button(text : "Share files", actionPerformed : shareFiles)
|
||||
button(text : "Share", actionPerformed : shareFiles)
|
||||
button(text : "Add Comment", enabled : bind {model.addCommentButtonEnabled}, addCommentAction)
|
||||
button(text : "Certify", enabled : bind {model.addCommentButtonEnabled}, issueCertificateAction)
|
||||
}
|
||||
@@ -433,6 +434,8 @@ class MainFrameView {
|
||||
button(text : "Subscribe", enabled : bind {model.subscribeButtonEnabled}, constraints : gbc(gridx: 0, gridy : 0), subscribeAction)
|
||||
button(text : "Mark Neutral", enabled : bind {model.markNeutralFromTrustedButtonEnabled}, constraints : gbc(gridx: 1, gridy: 0), markNeutralFromTrustedAction)
|
||||
button(text : "Mark Distrusted", enabled : bind {model.markDistrustedButtonEnabled}, constraints : gbc(gridx: 2, gridy:0), markDistrustedAction)
|
||||
button(text : "Browse", constraints:gbc(gridx:3, gridy:0), browseFromTrustedAction)
|
||||
button(text : "Chat", constraints : gbc(gridx:4, gridy:0), chatFromTrustedAction)
|
||||
}
|
||||
}
|
||||
panel (border : etchedBorder()){
|
||||
@@ -475,6 +478,15 @@ class MainFrameView {
|
||||
}
|
||||
}
|
||||
}
|
||||
panel(constraints : "chat window") {
|
||||
borderLayout()
|
||||
tabbedPane(id : "chat-tabs", constraints : BorderLayout.CENTER)
|
||||
panel(constraints : BorderLayout.SOUTH) {
|
||||
button(text : "Start Chat Server", enabled : bind {!model.chatServerRunning}, startChatServerAction)
|
||||
button(text : "Stop Chat Server", enabled : bind {model.chatServerRunning}, stopChatServerAction)
|
||||
button(text : "Connect To Remote Server", connectChatServerAction)
|
||||
}
|
||||
}
|
||||
}
|
||||
panel (border: etchedBorder(), constraints : BorderLayout.SOUTH) {
|
||||
borderLayout()
|
||||
@@ -499,7 +511,9 @@ class MainFrameView {
|
||||
public boolean importData(TransferHandler.TransferSupport support) {
|
||||
def files = support.getTransferable().getTransferData(DataFlavor.javaFileListFlavor)
|
||||
files.each {
|
||||
model.core.eventBus.publish(new FileSharedEvent(file : it))
|
||||
File canonical = it.getCanonicalFile()
|
||||
model.core.fileManager.negativeTree.remove(canonical)
|
||||
model.core.eventBus.publish(new FileSharedEvent(file : canonical))
|
||||
}
|
||||
showUploadsWindow.call()
|
||||
true
|
||||
@@ -767,6 +781,34 @@ class MainFrameView {
|
||||
model.markNeutralFromTrustedButtonEnabled = true
|
||||
}
|
||||
})
|
||||
|
||||
JPopupMenu trustMenu = new JPopupMenu()
|
||||
JMenuItem subscribeItem = new JMenuItem("Subscribe")
|
||||
subscribeItem.addActionListener({mvcGroup.controller.subscribe()})
|
||||
trustMenu.add(subscribeItem)
|
||||
JMenuItem markNeutralItem = new JMenuItem("Mark Neutral")
|
||||
markNeutralItem.addActionListener({mvcGroup.controller.markNeutralFromTrusted()})
|
||||
trustMenu.add(markNeutralItem)
|
||||
JMenuItem markDistrustedItem = new JMenuItem("Mark Distrusted")
|
||||
markDistrustedItem.addActionListener({mvcGroup.controller.markDistrusted()})
|
||||
trustMenu.add(markDistrustedItem)
|
||||
JMenuItem browseItem = new JMenuItem("Browse")
|
||||
browseItem.addActionListener({mvcGroup.controller.browseFromTrusted()})
|
||||
trustMenu.add(browseItem)
|
||||
JMenuItem chatItem = new JMenuItem("Chat")
|
||||
chatItem.addActionListener({mvcGroup.controller.chatFromTrusted()})
|
||||
trustMenu.add(chatItem)
|
||||
|
||||
trustedTable.addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.isPopupTrigger() || e.button == MouseEvent.BUTTON3)
|
||||
showPopupMenu(trustMenu, e)
|
||||
}
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (e.isPopupTrigger() || e.button == MouseEvent.BUTTON3)
|
||||
showPopupMenu(trustMenu, e)
|
||||
}
|
||||
})
|
||||
|
||||
// distrusted table
|
||||
def distrustedTable = builder.getVariable("distrusted-table")
|
||||
@@ -986,6 +1028,7 @@ class MainFrameView {
|
||||
model.uploadsPaneButtonEnabled = true
|
||||
model.monitorPaneButtonEnabled = true
|
||||
model.trustPaneButtonEnabled = true
|
||||
model.chatPaneButtonEnabled = true
|
||||
}
|
||||
|
||||
def showDownloadsWindow = {
|
||||
@@ -996,6 +1039,7 @@ class MainFrameView {
|
||||
model.uploadsPaneButtonEnabled = true
|
||||
model.monitorPaneButtonEnabled = true
|
||||
model.trustPaneButtonEnabled = true
|
||||
model.chatPaneButtonEnabled = true
|
||||
}
|
||||
|
||||
def showUploadsWindow = {
|
||||
@@ -1006,6 +1050,7 @@ class MainFrameView {
|
||||
model.uploadsPaneButtonEnabled = false
|
||||
model.monitorPaneButtonEnabled = true
|
||||
model.trustPaneButtonEnabled = true
|
||||
model.chatPaneButtonEnabled = true
|
||||
}
|
||||
|
||||
def showMonitorWindow = {
|
||||
@@ -1016,6 +1061,7 @@ class MainFrameView {
|
||||
model.uploadsPaneButtonEnabled = true
|
||||
model.monitorPaneButtonEnabled = false
|
||||
model.trustPaneButtonEnabled = true
|
||||
model.chatPaneButtonEnabled = true
|
||||
}
|
||||
|
||||
def showTrustWindow = {
|
||||
@@ -1026,6 +1072,18 @@ class MainFrameView {
|
||||
model.uploadsPaneButtonEnabled = true
|
||||
model.monitorPaneButtonEnabled = true
|
||||
model.trustPaneButtonEnabled = false
|
||||
model.chatPaneButtonEnabled = true
|
||||
}
|
||||
|
||||
def showChatWindow = {
|
||||
def cardsPanel = builder.getVariable("cards-panel")
|
||||
cardsPanel.getLayout().show(cardsPanel, "chat window")
|
||||
model.searchesPaneButtonEnabled = true
|
||||
model.downloadsPaneButtonEnabled = true
|
||||
model.uploadsPaneButtonEnabled = true
|
||||
model.monitorPaneButtonEnabled = true
|
||||
model.trustPaneButtonEnabled = true
|
||||
model.chatPaneButtonEnabled = false
|
||||
}
|
||||
|
||||
def showSharedFilesTable = {
|
||||
@@ -1043,13 +1101,14 @@ class MainFrameView {
|
||||
def shareFiles = {
|
||||
def chooser = new JFileChooser()
|
||||
chooser.setFileHidingEnabled(!model.core.muOptions.shareHiddenFiles)
|
||||
chooser.setDialogTitle("Select file to share")
|
||||
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY)
|
||||
chooser.setDialogTitle("Select files or directories to share")
|
||||
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES)
|
||||
chooser.setMultiSelectionEnabled(true)
|
||||
int rv = chooser.showOpenDialog(null)
|
||||
if (rv == JFileChooser.APPROVE_OPTION) {
|
||||
chooser.getSelectedFiles().each {
|
||||
File canonical = it.getCanonicalFile()
|
||||
model.core.fileManager.negativeTree.remove(canonical)
|
||||
model.core.eventBus.publish(new FileSharedEvent(file : canonical))
|
||||
}
|
||||
}
|
||||
|
@@ -33,6 +33,7 @@ class OptionsView {
|
||||
def u
|
||||
def bandwidth
|
||||
def trust
|
||||
def chat
|
||||
|
||||
def retryField
|
||||
def updateField
|
||||
@@ -71,6 +72,11 @@ class OptionsView {
|
||||
def allowTrustListsCheckbox
|
||||
def trustListIntervalField
|
||||
|
||||
def startChatServerCheckbox
|
||||
def maxChatConnectionsField
|
||||
def advertiseChatCheckbox
|
||||
def maxChatLinesField
|
||||
|
||||
def buttonsPanel
|
||||
|
||||
def mainFrame
|
||||
@@ -267,6 +273,23 @@ class OptionsView {
|
||||
}
|
||||
panel(constraints : gbc(gridx: 0, gridy : 1, weighty: 100))
|
||||
}
|
||||
|
||||
chat = builder.panel {
|
||||
gridBagLayout()
|
||||
panel (border : titledBorder(title : "Chat Settings", border : etchedBorder(), titlePosition : TitledBorder.TOP),
|
||||
constraints : gbc(gridx : 0, gridy : 0, fill : GridBagConstraints.HORIZONTAL, weightx: 100)) {
|
||||
gridBagLayout()
|
||||
label(text : "Start chat server on startup", constraints : gbc(gridx: 0, gridy: 0, anchor: GridBagConstraints.LINE_START, weightx: 100))
|
||||
startChatServerCheckbox = checkBox(selected : bind{model.startChatServer}, constraints : gbc(gridx:1, gridy:0, anchor:GridBagConstraints.LINE_END))
|
||||
label(text : "Maximum chat connections (-1 means unlimited)", constraints : gbc(gridx: 0, gridy:1, anchor:GridBagConstraints.LINE_START, weightx:100))
|
||||
maxChatConnectionsField = textField(text : bind {model.maxChatConnections}, constraints : gbc(gridx: 1, gridy : 1, anchor:GridBagConstraints.LINE_END))
|
||||
label(text : "Advertise chat ability in search results", constraints : gbc(gridx: 0, gridy:2, anchor:GridBagConstraints.LINE_START, weightx:100))
|
||||
advertiseChatCheckbox = checkBox(selected : bind{model.advertiseChat}, constraints : gbc(gridx:1, gridy:2, anchor:GridBagConstraints.LINE_END))
|
||||
label(text : "Maximum lines of scrollback (-1 means unlimited)", constraints : gbc(gridx:0, gridy:3, anchor : GridBagConstraints.LINE_START, weightx: 100))
|
||||
maxChatLinesField = textField(text : bind{model.maxChatLines}, constraints : gbc(gridx:1, gridy: 3, anchor: GridBagConstraints.LINE_END))
|
||||
}
|
||||
panel(constraints : gbc(gridx: 0, gridy : 1, weighty: 100))
|
||||
}
|
||||
|
||||
|
||||
buttonsPanel = builder.panel {
|
||||
@@ -286,6 +309,7 @@ class OptionsView {
|
||||
tabbedPane.addTab("Bandwidth", bandwidth)
|
||||
}
|
||||
tabbedPane.addTab("Trust", trust)
|
||||
tabbedPane.addTab("Chat", chat)
|
||||
|
||||
JPanel panel = new JPanel()
|
||||
panel.setLayout(new BorderLayout())
|
||||
|
@@ -74,6 +74,7 @@ class SearchTabView {
|
||||
closureColumn(header : "Sender", preferredWidth : 500, type: String, read : {row -> row.getHumanReadableName()})
|
||||
closureColumn(header : "Results", preferredWidth : 20, type: Integer, read : {row -> model.sendersBucket[row].size()})
|
||||
closureColumn(header : "Browse", preferredWidth : 20, type: Boolean, read : {row -> model.sendersBucket[row].first().browse})
|
||||
closureColumn(header : "Chat", preferredWidth : 20, type : Boolean, read : {row -> model.sendersBucket[row].first().chat})
|
||||
closureColumn(header : "Trust", preferredWidth : 50, type: String, read : { row ->
|
||||
model.core.trustService.getLevel(row.destination).toString()
|
||||
})
|
||||
@@ -84,6 +85,7 @@ class SearchTabView {
|
||||
gridLayout(rows: 1, cols : 2)
|
||||
panel (border : etchedBorder()){
|
||||
button(text : "Browse Host", enabled : bind {model.browseActionEnabled}, browseAction)
|
||||
button(text : "Chat", enabled : bind{model.chatActionEnabled}, chatAction)
|
||||
}
|
||||
panel (border : etchedBorder()){
|
||||
button(text : "Trust", enabled: bind {model.trustButtonsEnabled }, trustAction)
|
||||
@@ -154,6 +156,14 @@ class SearchTabView {
|
||||
}
|
||||
count
|
||||
})
|
||||
closureColumn(header : "Chat Hosts", preferredWidth : 20, type : Integer, read : {
|
||||
int count = 0
|
||||
model.hashBucket[it].each {
|
||||
if (it.chat)
|
||||
count++
|
||||
}
|
||||
count
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -177,6 +187,7 @@ class SearchTabView {
|
||||
tableModel(list : model.senders2) {
|
||||
closureColumn(header : "Sender", preferredWidth : 350, type : String, read : {it.sender.getHumanReadableName()})
|
||||
closureColumn(header : "Browse", preferredWidth : 20, type : Boolean, read : {it.browse})
|
||||
closureColumn(header : "Chat", preferredWidth : 20, type : Boolean, read : {it.chat})
|
||||
closureColumn(header : "Comment", preferredWidth : 20, type : Boolean, read : {it.comment != null})
|
||||
closureColumn(header : "Certificates", preferredWidth : 20, type: Integer, read : {it.certificates})
|
||||
closureColumn(header : "Trust", preferredWidth : 50, type : String, read : {
|
||||
@@ -189,6 +200,7 @@ class SearchTabView {
|
||||
gridLayout(rows : 1, cols : 2)
|
||||
panel (border : etchedBorder()) {
|
||||
button(text : "Browse Host", enabled : bind {model.browseActionEnabled}, browseAction)
|
||||
button(text : "Chat", enabled : bind{model.chatActionEnabled}, chatAction)
|
||||
button(text : "View Comment", enabled : bind {model.viewCommentActionEnabled}, showCommentAction)
|
||||
button(text : "View Certificates", enabled : bind {model.viewCertificatesActionEnabled}, viewCertificatesAction)
|
||||
}
|
||||
@@ -314,10 +326,12 @@ class SearchTabView {
|
||||
if (row < 0) {
|
||||
model.trustButtonsEnabled = false
|
||||
model.browseActionEnabled = false
|
||||
model.chatActionEnabled = false
|
||||
return
|
||||
} else {
|
||||
Persona sender = model.senders[row]
|
||||
model.browseActionEnabled = model.sendersBucket[sender].first().browse
|
||||
model.chatActionEnabled = model.sendersBucket[sender].first().chat
|
||||
model.trustButtonsEnabled = true
|
||||
model.results.clear()
|
||||
model.results.addAll(model.sendersBucket[sender])
|
||||
@@ -337,6 +351,7 @@ class SearchTabView {
|
||||
if (e == null) {
|
||||
model.trustButtonsEnabled = false
|
||||
model.browseActionEnabled = false
|
||||
model.chatActionEnabled = false
|
||||
model.viewCertificatesActionEnabled = false
|
||||
return
|
||||
}
|
||||
@@ -370,12 +385,14 @@ class SearchTabView {
|
||||
int row = selectedSenderRow()
|
||||
if (row < 0 || model.senders2[row] == null) {
|
||||
model.browseActionEnabled = false
|
||||
model.chatActionEnabled = false
|
||||
model.viewCertificatesActionEnabled = false
|
||||
model.trustButtonsEnabled = false
|
||||
model.viewCommentActionEnabled = false
|
||||
return
|
||||
}
|
||||
model.browseActionEnabled = model.senders2[row].browse
|
||||
model.chatActionEnabled = model.senders2[row].chat
|
||||
model.trustButtonsEnabled = true
|
||||
model.viewCommentActionEnabled = model.senders2[row].comment != null
|
||||
model.viewCertificatesActionEnabled = model.senders2[row].certificates > 0
|
||||
|
@@ -19,6 +19,7 @@ class UISettings {
|
||||
boolean clearUploads
|
||||
boolean storeSearchHistory
|
||||
boolean groupByFile
|
||||
int maxChatLines
|
||||
Set<String> searchHistory
|
||||
Set<String> openTabs
|
||||
|
||||
@@ -38,6 +39,7 @@ class UISettings {
|
||||
clearUploads = Boolean.parseBoolean(props.getProperty("clearUploads","false"))
|
||||
storeSearchHistory = Boolean.parseBoolean(props.getProperty("storeSearchHistory","true"))
|
||||
groupByFile = Boolean.parseBoolean(props.getProperty("groupByFile","false"))
|
||||
maxChatLines = Integer.parseInt(props.getProperty("maxChatLines","-1"))
|
||||
|
||||
searchHistory = DataUtil.readEncodedSet(props, "searchHistory")
|
||||
openTabs = DataUtil.readEncodedSet(props, "openTabs")
|
||||
@@ -59,6 +61,7 @@ class UISettings {
|
||||
props.setProperty("clearUploads", String.valueOf(clearUploads))
|
||||
props.setProperty("storeSearchHistory", String.valueOf(storeSearchHistory))
|
||||
props.setProperty("groupByFile", String.valueOf(groupByFile))
|
||||
props.setProperty("maxChatLines", String.valueOf(maxChatLines))
|
||||
if (font != null)
|
||||
props.setProperty("font", font)
|
||||
|
||||
|
Reference in New Issue
Block a user