wip on hooking UI with core
This commit is contained in:
@@ -20,6 +20,7 @@ import groovy.util.logging.Log
|
|||||||
import net.i2p.crypto.DSAEngine
|
import net.i2p.crypto.DSAEngine
|
||||||
import net.i2p.data.Base64
|
import net.i2p.data.Base64
|
||||||
import net.i2p.data.Signature
|
import net.i2p.data.Signature
|
||||||
|
import net.i2p.data.SigningPrivateKey
|
||||||
|
|
||||||
@Log
|
@Log
|
||||||
class ChatConnection implements Closeable {
|
class ChatConnection implements Closeable {
|
||||||
@@ -220,6 +221,23 @@ class ChatConnection implements Closeable {
|
|||||||
DSAEngine.getInstance().verifySignature(signature, signed, spk)
|
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) {
|
void sendChat(ChatMessageEvent e) {
|
||||||
def chat = [:]
|
def chat = [:]
|
||||||
chat.type = "Chat"
|
chat.type = "Chat"
|
||||||
|
@@ -4,14 +4,49 @@ import griffon.core.artifact.GriffonController
|
|||||||
import griffon.core.controller.ControllerAction
|
import griffon.core.controller.ControllerAction
|
||||||
import griffon.inject.MVCMember
|
import griffon.inject.MVCMember
|
||||||
import griffon.metadata.ArtifactProviderFor
|
import griffon.metadata.ArtifactProviderFor
|
||||||
|
import net.i2p.crypto.DSAEngine
|
||||||
|
import net.i2p.data.DataHelper
|
||||||
|
import net.i2p.data.Signature
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets
|
||||||
|
|
||||||
import javax.annotation.Nonnull
|
import javax.annotation.Nonnull
|
||||||
|
|
||||||
|
import com.muwire.core.chat.ChatConnection
|
||||||
|
import com.muwire.core.chat.ChatMessageEvent
|
||||||
|
import com.muwire.core.chat.ChatServer
|
||||||
|
|
||||||
@ArtifactProviderFor(GriffonController)
|
@ArtifactProviderFor(GriffonController)
|
||||||
class ChatRoomController {
|
class ChatRoomController {
|
||||||
@MVCMember @Nonnull
|
@MVCMember @Nonnull
|
||||||
ChatRoomModel model
|
ChatRoomModel model
|
||||||
|
@MVCMember @Nonnull
|
||||||
|
ChatRoomView view
|
||||||
|
|
||||||
@ControllerAction
|
@ControllerAction
|
||||||
void say() {
|
void say() {
|
||||||
|
String words = view.sayField.text
|
||||||
|
view.sayField.setText(null)
|
||||||
|
|
||||||
|
long now = System.currentTimeMillis()
|
||||||
|
UUID uuid = UUID.randomUUID()
|
||||||
|
String room = model.console ? ChatServer.CONSOLE : model.room
|
||||||
|
|
||||||
|
byte [] sig = ChatConnection.sign(uuid, now, room, words, model.core.me, mvcGroup.parentGroup.model.host, model.core.spk)
|
||||||
|
|
||||||
|
def event = new ChatMessageEvent(uuid : uuid,
|
||||||
|
payload : words,
|
||||||
|
sender : model.core.me,
|
||||||
|
host : mvcGroup.parentGroup.model.host,
|
||||||
|
room : room,
|
||||||
|
chatTime : now,
|
||||||
|
sig : sig)
|
||||||
|
|
||||||
|
model.core.eventBus.publish(event)
|
||||||
|
|
||||||
|
String toShow = DataHelper.formatTime(now) + " <" + model.core.me.getHumanReadableName() + "> "+words
|
||||||
|
|
||||||
|
view.roomTextArea.append(toShow)
|
||||||
|
view.roomTextArea.append('\n')
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -11,4 +11,7 @@ class ChatRoomModel {
|
|||||||
Core core
|
Core core
|
||||||
String tabName
|
String tabName
|
||||||
String room
|
String room
|
||||||
|
boolean console
|
||||||
|
|
||||||
|
def members = []
|
||||||
}
|
}
|
@@ -3,6 +3,8 @@ package com.muwire.gui
|
|||||||
import griffon.core.artifact.GriffonView
|
import griffon.core.artifact.GriffonView
|
||||||
import griffon.inject.MVCMember
|
import griffon.inject.MVCMember
|
||||||
import griffon.metadata.ArtifactProviderFor
|
import griffon.metadata.ArtifactProviderFor
|
||||||
|
|
||||||
|
import javax.swing.JSplitPane
|
||||||
import javax.swing.SwingConstants
|
import javax.swing.SwingConstants
|
||||||
|
|
||||||
import java.awt.BorderLayout
|
import java.awt.BorderLayout
|
||||||
@@ -20,17 +22,48 @@ class ChatRoomView {
|
|||||||
|
|
||||||
def pane
|
def pane
|
||||||
def parent
|
def parent
|
||||||
|
def sayField
|
||||||
|
def roomTextArea
|
||||||
|
|
||||||
void initUI() {
|
void initUI() {
|
||||||
pane = builder.panel {
|
int rowHeight = application.context.get("row-height")
|
||||||
borderLayout()
|
if (model.console) {
|
||||||
panel(constraints : BorderLayout.CENTER) {
|
pane = builder.panel {
|
||||||
textArea(editable : false)
|
|
||||||
}
|
|
||||||
panel(constraints : BorderLayout.SOUTH) {
|
|
||||||
borderLayout()
|
borderLayout()
|
||||||
textField(actionPerformed : {controller.say()}, constraints : BorderLayout.CENTER)
|
panel(constraints : BorderLayout.CENTER) {
|
||||||
button(text : "Say", constraints : BorderLayout.EAST, sayAction)
|
gridLayout(rows : 1, cols : 1)
|
||||||
|
roomTextArea = textArea(editable : false, lineWrap : true, wrapStyleWord : true)
|
||||||
|
}
|
||||||
|
panel(constraints : BorderLayout.SOUTH) {
|
||||||
|
borderLayout()
|
||||||
|
sayField = textField(actionPerformed : {controller.say()}, constraints : BorderLayout.CENTER)
|
||||||
|
button(text : "Say", constraints : BorderLayout.EAST, sayAction)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
pane = builder.panel {
|
||||||
|
borderLayout()
|
||||||
|
panel(constraints : BorderLayout.CENTER) {
|
||||||
|
splitPane(orientation : JSplitPane.HORIZONTAL_SPLIT, continuousLayout : true, dividerLocation : 200)
|
||||||
|
panel {
|
||||||
|
table(autoCreateRowSorter : true, rowHeight : rowHeight) {
|
||||||
|
tableModel(list : model.members) {
|
||||||
|
closureColumn(header : "Name", type: String, read : {it.getHumanReadableName()})
|
||||||
|
closureColumn(header : "Trust Status", type : String, read : {String.valueOf(model.core.trustService.getLevel(it.destination))})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panel {
|
||||||
|
gridLayout(rows : 1, cols : 1)
|
||||||
|
roomTextArea = textArea(editable : false, lineWrap : true, wrapStyleWord : true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panel(constraints : BorderLayout.SOUTH) {
|
||||||
|
borderLayout()
|
||||||
|
sayField = textField(actionPerformed : {controller.say()}, constraints : BorderLayout.CENTER)
|
||||||
|
button(text : "Say", constraints : BorderLayout.EAST, sayAction)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -50,7 +83,8 @@ class ChatRoomView {
|
|||||||
button(icon : imageIcon("/close_tab.png"), preferredSize: [20, 20], constraints : BorderLayout.EAST,
|
button(icon : imageIcon("/close_tab.png"), preferredSize: [20, 20], constraints : BorderLayout.EAST,
|
||||||
actionPerformed : closeTab )
|
actionPerformed : closeTab )
|
||||||
}
|
}
|
||||||
parent.setTabComponentAt(index, tabPanel)
|
if (!model.console)
|
||||||
|
parent.setTabComponentAt(index, tabPanel)
|
||||||
}
|
}
|
||||||
|
|
||||||
def closeTab = {
|
def closeTab = {
|
||||||
|
@@ -54,6 +54,7 @@ class ChatServerView {
|
|||||||
params['core'] = model.core
|
params['core'] = model.core
|
||||||
params['tabName'] = model.host.getHumanReadableName() + "-chat-rooms"
|
params['tabName'] = model.host.getHumanReadableName() + "-chat-rooms"
|
||||||
params['room'] = 'Console'
|
params['room'] = 'Console'
|
||||||
|
params['console'] = true
|
||||||
mvcGroup.createMVCGroup("chat-room","Console", params)
|
mvcGroup.createMVCGroup("chat-room","Console", params)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user