2022-09-05 15:02:37 +02:00
|
|
|
// Copyright (c) 2022, Přemysl Eric Janouch <p@janouch.name>
|
|
|
|
// SPDX-License-Identifier: 0BSD
|
|
|
|
|
Start X11 and web frontends for xC
For this, we needed a wire protocol. After surveying available options,
it was decided to implement an XDR-like protocol code generator
in portable AWK. It now has two backends, per each of:
- xF, the X11 frontend, is in C, and is meant to be the primary
user interface in the future.
- xP, the web frontend, relies on a protocol proxy written in Go,
and is meant for use on-the-go (no pun intended).
They are very much work-in-progress proofs of concept right now,
and the relay protocol is certain to change.
2022-08-08 04:39:20 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-09-14 07:10:49 +02:00
|
|
|
"bufio"
|
Start X11 and web frontends for xC
For this, we needed a wire protocol. After surveying available options,
it was decided to implement an XDR-like protocol code generator
in portable AWK. It now has two backends, per each of:
- xF, the X11 frontend, is in C, and is meant to be the primary
user interface in the future.
- xP, the web frontend, relies on a protocol proxy written in Go,
and is meant for use on-the-go (no pun intended).
They are very much work-in-progress proofs of concept right now,
and the relay protocol is certain to change.
2022-08-08 04:39:20 +02:00
|
|
|
"context"
|
|
|
|
"encoding/binary"
|
|
|
|
"encoding/json"
|
2022-09-15 22:45:14 +02:00
|
|
|
"flag"
|
Start X11 and web frontends for xC
For this, we needed a wire protocol. After surveying available options,
it was decided to implement an XDR-like protocol code generator
in portable AWK. It now has two backends, per each of:
- xF, the X11 frontend, is in C, and is meant to be the primary
user interface in the future.
- xP, the web frontend, relies on a protocol proxy written in Go,
and is meant for use on-the-go (no pun intended).
They are very much work-in-progress proofs of concept right now,
and the relay protocol is certain to change.
2022-08-08 04:39:20 +02:00
|
|
|
"fmt"
|
|
|
|
"html/template"
|
|
|
|
"io"
|
|
|
|
"log"
|
|
|
|
"net"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
2022-09-13 21:44:20 +02:00
|
|
|
"nhooyr.io/websocket"
|
Start X11 and web frontends for xC
For this, we needed a wire protocol. After surveying available options,
it was decided to implement an XDR-like protocol code generator
in portable AWK. It now has two backends, per each of:
- xF, the X11 frontend, is in C, and is meant to be the primary
user interface in the future.
- xP, the web frontend, relies on a protocol proxy written in Go,
and is meant for use on-the-go (no pun intended).
They are very much work-in-progress proofs of concept right now,
and the relay protocol is certain to change.
2022-08-08 04:39:20 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2022-09-15 22:45:14 +02:00
|
|
|
debug = flag.Bool("debug", false, "enable debug output")
|
|
|
|
|
Start X11 and web frontends for xC
For this, we needed a wire protocol. After surveying available options,
it was decided to implement an XDR-like protocol code generator
in portable AWK. It now has two backends, per each of:
- xF, the X11 frontend, is in C, and is meant to be the primary
user interface in the future.
- xP, the web frontend, relies on a protocol proxy written in Go,
and is meant for use on-the-go (no pun intended).
They are very much work-in-progress proofs of concept right now,
and the relay protocol is certain to change.
2022-08-08 04:39:20 +02:00
|
|
|
addressBind string
|
|
|
|
addressConnect string
|
2022-09-08 15:13:20 +02:00
|
|
|
addressWS string
|
Start X11 and web frontends for xC
For this, we needed a wire protocol. After surveying available options,
it was decided to implement an XDR-like protocol code generator
in portable AWK. It now has two backends, per each of:
- xF, the X11 frontend, is in C, and is meant to be the primary
user interface in the future.
- xP, the web frontend, relies on a protocol proxy written in Go,
and is meant for use on-the-go (no pun intended).
They are very much work-in-progress proofs of concept right now,
and the relay protocol is certain to change.
2022-08-08 04:39:20 +02:00
|
|
|
)
|
|
|
|
|
2022-09-14 00:47:46 +02:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2022-09-15 22:45:14 +02:00
|
|
|
func relayReadFrame(r io.Reader) []byte {
|
2022-09-14 00:47:46 +02:00
|
|
|
var length uint32
|
2022-09-14 07:10:49 +02:00
|
|
|
if err := binary.Read(r, binary.BigEndian, &length); err != nil {
|
2022-09-14 00:47:46 +02:00
|
|
|
log.Println("Event receive failed: " + err.Error())
|
|
|
|
return nil
|
Start X11 and web frontends for xC
For this, we needed a wire protocol. After surveying available options,
it was decided to implement an XDR-like protocol code generator
in portable AWK. It now has two backends, per each of:
- xF, the X11 frontend, is in C, and is meant to be the primary
user interface in the future.
- xP, the web frontend, relies on a protocol proxy written in Go,
and is meant for use on-the-go (no pun intended).
They are very much work-in-progress proofs of concept right now,
and the relay protocol is certain to change.
2022-08-08 04:39:20 +02:00
|
|
|
}
|
2022-09-14 00:47:46 +02:00
|
|
|
b := make([]byte, length)
|
2022-09-14 07:10:49 +02:00
|
|
|
if _, err := io.ReadFull(r, b); err != nil {
|
2022-09-14 00:47:46 +02:00
|
|
|
log.Println("Event receive failed: " + err.Error())
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-09-15 22:45:14 +02:00
|
|
|
if *debug {
|
|
|
|
log.Printf("<? %v\n", b)
|
2022-09-14 00:47:46 +02:00
|
|
|
|
2022-09-15 22:45:14 +02:00
|
|
|
var m RelayEventMessage
|
|
|
|
if after, ok := m.ConsumeFrom(b); !ok {
|
|
|
|
log.Println("Event deserialization failed")
|
|
|
|
return nil
|
|
|
|
} else if len(after) != 0 {
|
|
|
|
log.Println("Event deserialization failed: trailing data")
|
|
|
|
return nil
|
|
|
|
}
|
Start X11 and web frontends for xC
For this, we needed a wire protocol. After surveying available options,
it was decided to implement an XDR-like protocol code generator
in portable AWK. It now has two backends, per each of:
- xF, the X11 frontend, is in C, and is meant to be the primary
user interface in the future.
- xP, the web frontend, relies on a protocol proxy written in Go,
and is meant for use on-the-go (no pun intended).
They are very much work-in-progress proofs of concept right now,
and the relay protocol is certain to change.
2022-08-08 04:39:20 +02:00
|
|
|
|
2022-09-15 22:45:14 +02:00
|
|
|
j, err := m.MarshalJSON()
|
|
|
|
if err != nil {
|
|
|
|
log.Println("Event marshalling failed: " + err.Error())
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Printf("<- %s\n", j)
|
2022-09-14 00:47:46 +02:00
|
|
|
}
|
2022-09-15 22:45:14 +02:00
|
|
|
return b
|
2022-09-14 00:47:46 +02:00
|
|
|
}
|
Start X11 and web frontends for xC
For this, we needed a wire protocol. After surveying available options,
it was decided to implement an XDR-like protocol code generator
in portable AWK. It now has two backends, per each of:
- xF, the X11 frontend, is in C, and is meant to be the primary
user interface in the future.
- xP, the web frontend, relies on a protocol proxy written in Go,
and is meant for use on-the-go (no pun intended).
They are very much work-in-progress proofs of concept right now,
and the relay protocol is certain to change.
2022-08-08 04:39:20 +02:00
|
|
|
|
2022-09-14 00:47:46 +02:00
|
|
|
func relayMakeReceiver(ctx context.Context, conn net.Conn) <-chan []byte {
|
2022-09-15 22:45:14 +02:00
|
|
|
// The usual event message rarely gets above 1 kilobyte,
|
|
|
|
// thus this is set to buffer up at most 1 megabyte or so.
|
|
|
|
p := make(chan []byte, 1000)
|
|
|
|
r := bufio.NewReaderSize(conn, 65536)
|
2022-09-14 00:47:46 +02:00
|
|
|
go func() {
|
|
|
|
defer close(p)
|
|
|
|
for {
|
2022-09-15 22:45:14 +02:00
|
|
|
j := relayReadFrame(r)
|
2022-09-14 00:47:46 +02:00
|
|
|
if j == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
select {
|
|
|
|
case p <- j:
|
|
|
|
case <-ctx.Done():
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
|
|
|
func relayWriteJSON(conn net.Conn, j []byte) bool {
|
Start X11 and web frontends for xC
For this, we needed a wire protocol. After surveying available options,
it was decided to implement an XDR-like protocol code generator
in portable AWK. It now has two backends, per each of:
- xF, the X11 frontend, is in C, and is meant to be the primary
user interface in the future.
- xP, the web frontend, relies on a protocol proxy written in Go,
and is meant for use on-the-go (no pun intended).
They are very much work-in-progress proofs of concept right now,
and the relay protocol is certain to change.
2022-08-08 04:39:20 +02:00
|
|
|
var m RelayCommandMessage
|
2022-09-14 00:47:46 +02:00
|
|
|
if err := json.Unmarshal(j, &m); err != nil {
|
Start X11 and web frontends for xC
For this, we needed a wire protocol. After surveying available options,
it was decided to implement an XDR-like protocol code generator
in portable AWK. It now has two backends, per each of:
- xF, the X11 frontend, is in C, and is meant to be the primary
user interface in the future.
- xP, the web frontend, relies on a protocol proxy written in Go,
and is meant for use on-the-go (no pun intended).
They are very much work-in-progress proofs of concept right now,
and the relay protocol is certain to change.
2022-08-08 04:39:20 +02:00
|
|
|
log.Println("Command unmarshalling failed: " + err.Error())
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
b, ok := m.AppendTo(make([]byte, 4))
|
|
|
|
if !ok {
|
|
|
|
log.Println("Command serialization failed")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
binary.BigEndian.PutUint32(b[:4], uint32(len(b)-4))
|
|
|
|
if _, err := conn.Write(b); err != nil {
|
|
|
|
log.Println("Command send failed: " + err.Error())
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-09-15 22:45:14 +02:00
|
|
|
if *debug {
|
|
|
|
log.Printf("-> %v\n", b)
|
|
|
|
}
|
Start X11 and web frontends for xC
For this, we needed a wire protocol. After surveying available options,
it was decided to implement an XDR-like protocol code generator
in portable AWK. It now has two backends, per each of:
- xF, the X11 frontend, is in C, and is meant to be the primary
user interface in the future.
- xP, the web frontend, relies on a protocol proxy written in Go,
and is meant for use on-the-go (no pun intended).
They are very much work-in-progress proofs of concept right now,
and the relay protocol is certain to change.
2022-08-08 04:39:20 +02:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2022-09-14 00:47:46 +02:00
|
|
|
// -----------------------------------------------------------------------------
|
Start X11 and web frontends for xC
For this, we needed a wire protocol. After surveying available options,
it was decided to implement an XDR-like protocol code generator
in portable AWK. It now has two backends, per each of:
- xF, the X11 frontend, is in C, and is meant to be the primary
user interface in the future.
- xP, the web frontend, relies on a protocol proxy written in Go,
and is meant for use on-the-go (no pun intended).
They are very much work-in-progress proofs of concept right now,
and the relay protocol is certain to change.
2022-08-08 04:39:20 +02:00
|
|
|
|
2022-09-14 00:47:46 +02:00
|
|
|
func clientReadJSON(ctx context.Context, ws *websocket.Conn) []byte {
|
|
|
|
t, j, err := ws.Read(ctx)
|
Start X11 and web frontends for xC
For this, we needed a wire protocol. After surveying available options,
it was decided to implement an XDR-like protocol code generator
in portable AWK. It now has two backends, per each of:
- xF, the X11 frontend, is in C, and is meant to be the primary
user interface in the future.
- xP, the web frontend, relies on a protocol proxy written in Go,
and is meant for use on-the-go (no pun intended).
They are very much work-in-progress proofs of concept right now,
and the relay protocol is certain to change.
2022-08-08 04:39:20 +02:00
|
|
|
if err != nil {
|
2022-09-14 00:47:46 +02:00
|
|
|
log.Println("Command receive failed: " + err.Error())
|
|
|
|
return nil
|
Start X11 and web frontends for xC
For this, we needed a wire protocol. After surveying available options,
it was decided to implement an XDR-like protocol code generator
in portable AWK. It now has two backends, per each of:
- xF, the X11 frontend, is in C, and is meant to be the primary
user interface in the future.
- xP, the web frontend, relies on a protocol proxy written in Go,
and is meant for use on-the-go (no pun intended).
They are very much work-in-progress proofs of concept right now,
and the relay protocol is certain to change.
2022-08-08 04:39:20 +02:00
|
|
|
}
|
2022-09-14 00:47:46 +02:00
|
|
|
if t != websocket.MessageText {
|
|
|
|
log.Println(
|
|
|
|
"Command receive failed: " + "binary messages are not supported")
|
|
|
|
return nil
|
|
|
|
}
|
2022-09-15 22:45:14 +02:00
|
|
|
|
|
|
|
if *debug {
|
|
|
|
log.Printf("?> %s\n", j)
|
|
|
|
}
|
2022-09-14 00:47:46 +02:00
|
|
|
return j
|
|
|
|
}
|
|
|
|
|
2022-09-15 22:45:14 +02:00
|
|
|
func clientWriteBinary(ctx context.Context, ws *websocket.Conn, b []byte) bool {
|
|
|
|
if err := ws.Write(ctx, websocket.MessageBinary, b); err != nil {
|
Start X11 and web frontends for xC
For this, we needed a wire protocol. After surveying available options,
it was decided to implement an XDR-like protocol code generator
in portable AWK. It now has two backends, per each of:
- xF, the X11 frontend, is in C, and is meant to be the primary
user interface in the future.
- xP, the web frontend, relies on a protocol proxy written in Go,
and is meant for use on-the-go (no pun intended).
They are very much work-in-progress proofs of concept right now,
and the relay protocol is certain to change.
2022-08-08 04:39:20 +02:00
|
|
|
log.Println("Event send failed: " + err.Error())
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2022-09-14 00:47:46 +02:00
|
|
|
func clientWriteError(ctx context.Context, ws *websocket.Conn, err error) bool {
|
2022-09-15 22:45:14 +02:00
|
|
|
b, ok := (&RelayEventMessage{
|
Start X11 and web frontends for xC
For this, we needed a wire protocol. After surveying available options,
it was decided to implement an XDR-like protocol code generator
in portable AWK. It now has two backends, per each of:
- xF, the X11 frontend, is in C, and is meant to be the primary
user interface in the future.
- xP, the web frontend, relies on a protocol proxy written in Go,
and is meant for use on-the-go (no pun intended).
They are very much work-in-progress proofs of concept right now,
and the relay protocol is certain to change.
2022-08-08 04:39:20 +02:00
|
|
|
EventSeq: 0,
|
|
|
|
Data: RelayEventData{
|
|
|
|
Interface: RelayEventDataError{
|
|
|
|
Event: RelayEventError,
|
|
|
|
CommandSeq: 0,
|
|
|
|
Error: err.Error(),
|
|
|
|
},
|
|
|
|
},
|
2022-09-15 22:45:14 +02:00
|
|
|
}).AppendTo(nil)
|
|
|
|
if ok {
|
|
|
|
log.Println("Event serialization failed")
|
Start X11 and web frontends for xC
For this, we needed a wire protocol. After surveying available options,
it was decided to implement an XDR-like protocol code generator
in portable AWK. It now has two backends, per each of:
- xF, the X11 frontend, is in C, and is meant to be the primary
user interface in the future.
- xP, the web frontend, relies on a protocol proxy written in Go,
and is meant for use on-the-go (no pun intended).
They are very much work-in-progress proofs of concept right now,
and the relay protocol is certain to change.
2022-08-08 04:39:20 +02:00
|
|
|
return false
|
|
|
|
}
|
2022-09-15 22:45:14 +02:00
|
|
|
return clientWriteBinary(ctx, ws, b)
|
Start X11 and web frontends for xC
For this, we needed a wire protocol. After surveying available options,
it was decided to implement an XDR-like protocol code generator
in portable AWK. It now has two backends, per each of:
- xF, the X11 frontend, is in C, and is meant to be the primary
user interface in the future.
- xP, the web frontend, relies on a protocol proxy written in Go,
and is meant for use on-the-go (no pun intended).
They are very much work-in-progress proofs of concept right now,
and the relay protocol is certain to change.
2022-08-08 04:39:20 +02:00
|
|
|
}
|
|
|
|
|
2022-09-13 21:44:20 +02:00
|
|
|
func handleWS(w http.ResponseWriter, r *http.Request) {
|
|
|
|
ws, err := websocket.Accept(w, r, &websocket.AcceptOptions{
|
|
|
|
InsecureSkipVerify: true,
|
2022-09-14 00:47:46 +02:00
|
|
|
// Note that Safari can be broken with compression.
|
|
|
|
CompressionMode: websocket.CompressionContextTakeover,
|
|
|
|
// This is for the payload; set higher to avoid overhead.
|
|
|
|
CompressionThreshold: 64 << 10,
|
2022-09-13 21:44:20 +02:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
log.Println("Client rejected: " + err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer ws.Close(websocket.StatusGoingAway, "Goodbye")
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(r.Context())
|
|
|
|
defer cancel()
|
|
|
|
|
Start X11 and web frontends for xC
For this, we needed a wire protocol. After surveying available options,
it was decided to implement an XDR-like protocol code generator
in portable AWK. It now has two backends, per each of:
- xF, the X11 frontend, is in C, and is meant to be the primary
user interface in the future.
- xP, the web frontend, relies on a protocol proxy written in Go,
and is meant for use on-the-go (no pun intended).
They are very much work-in-progress proofs of concept right now,
and the relay protocol is certain to change.
2022-08-08 04:39:20 +02:00
|
|
|
conn, err := net.Dial("tcp", addressConnect)
|
|
|
|
if err != nil {
|
2022-09-15 22:45:14 +02:00
|
|
|
log.Println("Connection failed: " + err.Error())
|
2022-09-14 00:47:46 +02:00
|
|
|
clientWriteError(ctx, ws, err)
|
Start X11 and web frontends for xC
For this, we needed a wire protocol. After surveying available options,
it was decided to implement an XDR-like protocol code generator
in portable AWK. It now has two backends, per each of:
- xF, the X11 frontend, is in C, and is meant to be the primary
user interface in the future.
- xP, the web frontend, relies on a protocol proxy written in Go,
and is meant for use on-the-go (no pun intended).
They are very much work-in-progress proofs of concept right now,
and the relay protocol is certain to change.
2022-08-08 04:39:20 +02:00
|
|
|
return
|
|
|
|
}
|
2022-09-14 00:47:46 +02:00
|
|
|
defer conn.Close()
|
Start X11 and web frontends for xC
For this, we needed a wire protocol. After surveying available options,
it was decided to implement an XDR-like protocol code generator
in portable AWK. It now has two backends, per each of:
- xF, the X11 frontend, is in C, and is meant to be the primary
user interface in the future.
- xP, the web frontend, relies on a protocol proxy written in Go,
and is meant for use on-the-go (no pun intended).
They are very much work-in-progress proofs of concept right now,
and the relay protocol is certain to change.
2022-08-08 04:39:20 +02:00
|
|
|
|
2022-09-15 22:45:14 +02:00
|
|
|
// To decrease latencies, events are received and decoded in parallel
|
|
|
|
// to their sending, and we try to batch them together.
|
|
|
|
relayFrames := relayMakeReceiver(ctx, conn)
|
|
|
|
batchFrames := func() []byte {
|
|
|
|
batch, ok := <-relayFrames
|
|
|
|
if !ok {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
Batch:
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case b, ok := <-relayFrames:
|
|
|
|
if !ok {
|
|
|
|
break Batch
|
|
|
|
}
|
|
|
|
batch = append(batch, b...)
|
|
|
|
default:
|
|
|
|
break Batch
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return batch
|
|
|
|
}
|
|
|
|
|
Start X11 and web frontends for xC
For this, we needed a wire protocol. After surveying available options,
it was decided to implement an XDR-like protocol code generator
in portable AWK. It now has two backends, per each of:
- xF, the X11 frontend, is in C, and is meant to be the primary
user interface in the future.
- xP, the web frontend, relies on a protocol proxy written in Go,
and is meant for use on-the-go (no pun intended).
They are very much work-in-progress proofs of concept right now,
and the relay protocol is certain to change.
2022-08-08 04:39:20 +02:00
|
|
|
// We don't need to intervene, so it's just two separate pipes so far.
|
|
|
|
go func() {
|
2022-09-14 00:47:46 +02:00
|
|
|
defer cancel()
|
|
|
|
for {
|
|
|
|
j := clientReadJSON(ctx, ws)
|
|
|
|
if j == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
relayWriteJSON(conn, j)
|
Start X11 and web frontends for xC
For this, we needed a wire protocol. After surveying available options,
it was decided to implement an XDR-like protocol code generator
in portable AWK. It now has two backends, per each of:
- xF, the X11 frontend, is in C, and is meant to be the primary
user interface in the future.
- xP, the web frontend, relies on a protocol proxy written in Go,
and is meant for use on-the-go (no pun intended).
They are very much work-in-progress proofs of concept right now,
and the relay protocol is certain to change.
2022-08-08 04:39:20 +02:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
go func() {
|
2022-09-14 00:47:46 +02:00
|
|
|
defer cancel()
|
|
|
|
for {
|
2022-09-15 22:45:14 +02:00
|
|
|
b := batchFrames()
|
|
|
|
if b == nil {
|
2022-09-14 00:47:46 +02:00
|
|
|
return
|
|
|
|
}
|
2022-09-15 22:45:14 +02:00
|
|
|
clientWriteBinary(ctx, ws, b)
|
Start X11 and web frontends for xC
For this, we needed a wire protocol. After surveying available options,
it was decided to implement an XDR-like protocol code generator
in portable AWK. It now has two backends, per each of:
- xF, the X11 frontend, is in C, and is meant to be the primary
user interface in the future.
- xP, the web frontend, relies on a protocol proxy written in Go,
and is meant for use on-the-go (no pun intended).
They are very much work-in-progress proofs of concept right now,
and the relay protocol is certain to change.
2022-08-08 04:39:20 +02:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
<-ctx.Done()
|
|
|
|
}
|
|
|
|
|
2022-09-14 00:47:46 +02:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
Start X11 and web frontends for xC
For this, we needed a wire protocol. After surveying available options,
it was decided to implement an XDR-like protocol code generator
in portable AWK. It now has two backends, per each of:
- xF, the X11 frontend, is in C, and is meant to be the primary
user interface in the future.
- xP, the web frontend, relies on a protocol proxy written in Go,
and is meant for use on-the-go (no pun intended).
They are very much work-in-progress proofs of concept right now,
and the relay protocol is certain to change.
2022-08-08 04:39:20 +02:00
|
|
|
var staticHandler = http.FileServer(http.Dir("."))
|
|
|
|
|
|
|
|
var page = template.Must(template.New("/").Parse(`<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>xP</title>
|
|
|
|
<meta charset="utf-8" />
|
2022-09-08 15:53:29 +02:00
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
Start X11 and web frontends for xC
For this, we needed a wire protocol. After surveying available options,
it was decided to implement an XDR-like protocol code generator
in portable AWK. It now has two backends, per each of:
- xF, the X11 frontend, is in C, and is meant to be the primary
user interface in the future.
- xP, the web frontend, relies on a protocol proxy written in Go,
and is meant for use on-the-go (no pun intended).
They are very much work-in-progress proofs of concept right now,
and the relay protocol is certain to change.
2022-08-08 04:39:20 +02:00
|
|
|
<link rel="stylesheet" href="xP.css" />
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<script src="mithril.js">
|
|
|
|
</script>
|
|
|
|
<script>
|
|
|
|
let proxy = '{{ . }}'
|
|
|
|
</script>
|
2022-09-15 22:45:14 +02:00
|
|
|
<script type="module" src="xP.js">
|
Start X11 and web frontends for xC
For this, we needed a wire protocol. After surveying available options,
it was decided to implement an XDR-like protocol code generator
in portable AWK. It now has two backends, per each of:
- xF, the X11 frontend, is in C, and is meant to be the primary
user interface in the future.
- xP, the web frontend, relies on a protocol proxy written in Go,
and is meant for use on-the-go (no pun intended).
They are very much work-in-progress proofs of concept right now,
and the relay protocol is certain to change.
2022-08-08 04:39:20 +02:00
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>`))
|
|
|
|
|
|
|
|
func handleDefault(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if r.URL.Path != "/" {
|
|
|
|
staticHandler.ServeHTTP(w, r)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-09-08 15:13:20 +02:00
|
|
|
wsURI := addressWS
|
|
|
|
if wsURI == "" {
|
|
|
|
wsURI = fmt.Sprintf("ws://%s/ws", r.Host)
|
|
|
|
}
|
Start X11 and web frontends for xC
For this, we needed a wire protocol. After surveying available options,
it was decided to implement an XDR-like protocol code generator
in portable AWK. It now has two backends, per each of:
- xF, the X11 frontend, is in C, and is meant to be the primary
user interface in the future.
- xP, the web frontend, relies on a protocol proxy written in Go,
and is meant for use on-the-go (no pun intended).
They are very much work-in-progress proofs of concept right now,
and the relay protocol is certain to change.
2022-08-08 04:39:20 +02:00
|
|
|
if err := page.Execute(w, wsURI); err != nil {
|
|
|
|
log.Println("Template execution failed: " + err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2022-09-15 22:45:14 +02:00
|
|
|
flag.Usage = func() {
|
|
|
|
fmt.Fprintf(flag.CommandLine.Output(),
|
|
|
|
"Usage: %s [OPTION...] BIND CONNECT [WSURI]\n\n", os.Args[0])
|
|
|
|
flag.PrintDefaults()
|
|
|
|
}
|
|
|
|
|
|
|
|
flag.Parse()
|
|
|
|
if flag.NArg() < 2 || flag.NArg() > 3 {
|
|
|
|
flag.Usage()
|
|
|
|
os.Exit(1)
|
Start X11 and web frontends for xC
For this, we needed a wire protocol. After surveying available options,
it was decided to implement an XDR-like protocol code generator
in portable AWK. It now has two backends, per each of:
- xF, the X11 frontend, is in C, and is meant to be the primary
user interface in the future.
- xP, the web frontend, relies on a protocol proxy written in Go,
and is meant for use on-the-go (no pun intended).
They are very much work-in-progress proofs of concept right now,
and the relay protocol is certain to change.
2022-08-08 04:39:20 +02:00
|
|
|
}
|
|
|
|
|
2022-09-15 22:45:14 +02:00
|
|
|
addressBind, addressConnect = flag.Arg(0), flag.Arg(1)
|
|
|
|
if flag.NArg() > 2 {
|
|
|
|
addressWS = flag.Arg(2)
|
2022-09-08 15:13:20 +02:00
|
|
|
}
|
Start X11 and web frontends for xC
For this, we needed a wire protocol. After surveying available options,
it was decided to implement an XDR-like protocol code generator
in portable AWK. It now has two backends, per each of:
- xF, the X11 frontend, is in C, and is meant to be the primary
user interface in the future.
- xP, the web frontend, relies on a protocol proxy written in Go,
and is meant for use on-the-go (no pun intended).
They are very much work-in-progress proofs of concept right now,
and the relay protocol is certain to change.
2022-08-08 04:39:20 +02:00
|
|
|
|
2022-09-13 21:44:20 +02:00
|
|
|
http.Handle("/ws", http.HandlerFunc(handleWS))
|
Start X11 and web frontends for xC
For this, we needed a wire protocol. After surveying available options,
it was decided to implement an XDR-like protocol code generator
in portable AWK. It now has two backends, per each of:
- xF, the X11 frontend, is in C, and is meant to be the primary
user interface in the future.
- xP, the web frontend, relies on a protocol proxy written in Go,
and is meant for use on-the-go (no pun intended).
They are very much work-in-progress proofs of concept right now,
and the relay protocol is certain to change.
2022-08-08 04:39:20 +02:00
|
|
|
http.Handle("/", http.HandlerFunc(handleDefault))
|
|
|
|
|
|
|
|
s := &http.Server{
|
|
|
|
Addr: addressBind,
|
|
|
|
ReadTimeout: 60 * time.Second,
|
|
|
|
WriteTimeout: 60 * time.Second,
|
|
|
|
MaxHeaderBytes: 32 << 10,
|
|
|
|
}
|
|
|
|
log.Fatal(s.ListenAndServe())
|
|
|
|
}
|