Room channel: other T5DE users' community products on their avatars
CI / build (push) Successful in 28s

The proxy follows the client's IMQ chat subscriptions and tells the hub which chats it's in (and the room, from
chat.getOrMakeChat). For the other T5DE users the hub says are in a chat, it gives the client the community
products it has packs for, as *use and *remove lines from them, and adds them to the whole outfits they send.
It also takes community products out of the outfit the client posts to IMVU's chat participant endpoint, which
had been sending them to IMVU.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
dhkatzandClaude Opus 5.5 committed 2026-10-29 18:14:44 -07:00
1 parent e394f1dc24
commit 93fa2f5d90
11 files changed
+858 -12

No files matched your search

+99
View File
@@ -474,3 +474,102 @@ func TestInterceptor(t *testing.T) {
t.Fatalf("changed: %q, server got %q, %v", b, gotBody, resp.Header)
}
}
// testWatcher records subscriptions, uppercases delivered messages, and delivers "welcome" on each subscription.
type testWatcher struct {
suffixFilter
mu sync.Mutex
events []string
}
func (w *testWatcher) add(e string) {
w.mu.Lock()
defer w.mu.Unlock()
w.events = append(w.events, e)
}
func (w *testWatcher) Subscribed(c *IMQConn, queues []string) {
w.add("sub " + strings.Join(queues, ","))
c.Deliver(imq.Delivered{UserID: "9", Queue: queues[0], Mount: "messages", Message: []byte("welcome")})
}
func (w *testWatcher) Unsubscribed(c *IMQConn, queues []string) {
w.add("unsub " + strings.Join(queues, ","))
}
func (w *testWatcher) Incoming(c *IMQConn, m imq.Delivered) []byte {
return bytes.ToUpper(m.Message)
}
func (w *testWatcher) Closed(c *IMQConn) { w.add("closed") }
func TestConnectWatchesSubscriptionsAndDeliveries(t *testing.T) {
gateway := httptest.NewUnstartedServer(nil)
gateway.StartTLS()
gateway.Close()
ln, err := tls.Listen("tcp", "127.0.0.1:0", &tls.Config{Certificates: gateway.TLS.Certificates})
if err != nil {
t.Fatal(err)
}
defer ln.Close()
delivered := imq.EncodeFrame(imq.G2cSendMessage, imq.Delivered{UserID: "/user/5", Queue: "/chat/1", Mount: "messages", Message: []byte("hello"), Sequence: 3}.Marshal())
go func() {
c, err := ln.Accept()
if err != nil {
return
}
defer c.Close()
buf := make([]byte, 4096)
c.Read(buf) // the subscription
c.Write(delivered)
c.SetReadDeadline(time.Now().Add(2 * time.Second))
c.Read(buf)
}()
roots := gateway.Client().Transport.(*http.Transport).TLSClientConfig.RootCAs
w := &testWatcher{}
p, logs := newProxy(t, &Server{TLSConfig: &tls.Config{RootCAs: roots}, IMQFilter: w,
Dial: func(ctx context.Context, network, addr string) (net.Conn, error) {
return net.Dial(network, ln.Addr().String())
}})
conn, err := net.Dial("tcp", p.Listener.Addr().String())
if err != nil {
t.Fatal(err)
}
defer conn.Close()
fmt.Fprintf(conn, "CONNECT example.com:443 HTTP/1.1\r\nProxy-authorization: %s\r\n\r\n", auth)
r := bufio.NewReader(conn)
for line, _ := r.ReadString('\n'); line != "\r\n"; line, _ = r.ReadString('\n') {
if line == "" {
t.Fatalf("no response; log %s", logs)
}
}
// queues: field 1; queues_with_results: field 2 (a Subscription, name in field 1).
sub := []byte{0x0a, 7}
sub = append(sub, "/chat/1"...)
sub = append(sub, 0x12, 9, 0x0a, 7)
sub = append(sub, "/chat/2"...)
conn.Write(imq.EncodeFrame(imq.C2gSubscribe, sub))
want := append(
imq.EncodeFrame(imq.G2cSendMessage, imq.Delivered{UserID: "9", Queue: "/chat/1", Mount: "messages", Message: []byte("welcome")}.Marshal()),
imq.EncodeFrame(imq.G2cSendMessage, imq.Delivered{UserID: "/user/5", Queue: "/chat/1", Mount: "messages", Message: []byte("HELLO"), Sequence: 3}.Marshal())...)
conn.SetReadDeadline(time.Now().Add(2 * time.Second))
got := make([]byte, len(want))
if _, err := io.ReadFull(r, got); err != nil {
t.Fatalf("%v; log %s", err, logs)
}
if !bytes.Equal(got, want) {
t.Fatalf("client got %q, want %q", got, want)
}
conn.Close()
for i := 0; i < 200; i++ {
w.mu.Lock()
n := len(w.events)
w.mu.Unlock()
if n == 2 {
break
}
time.Sleep(10 * time.Millisecond)
}
w.mu.Lock()
defer w.mu.Unlock()
if strings.Join(w.events, "; ") != "sub /chat/1,/chat/2; closed" {
t.Fatalf("events %q", w.events)
}
}