examples/chat: Make chat example compile

This commit is contained in:
2025-10-19 13:18:24 -04:00
parent e5d7ad0702
commit 14a317c2ab
7 changed files with 134 additions and 178 deletions

View File

@@ -28,7 +28,7 @@ func main() {
func host(address string, certPath, keyPath string) error {
keyPair, err := tls.LoadX509KeyPair(certPath, keyPath)
if err != nil { return err }
listener, err := hopp.ListenQUIC("quic", address, &tls.Config {
listener, err := hopp.ListenTLS("tcp", address, &tls.Config {
InsecureSkipVerify: true,
Certificates: []tls.Certificate { keyPair },
})
@@ -63,6 +63,7 @@ func (this *client) run() {
log.Println("accepted transaction")
if err != nil {
log.Printf("XXX %v failed: %v", this.conn.RemoteAddr(), err)
continue
}
go this.runTrans(trans)
}
@@ -70,7 +71,7 @@ func (this *client) run() {
func (this *client) runTrans(trans hopp.Trans) {
defer trans.Close()
message, err := chat.Receive(trans)
message, _, err := chat.Receive(trans)
if err != nil {
log.Printf(
"XXX %v transaction failed: %v",
@@ -97,7 +98,7 @@ func (this *client) transTalk(trans hopp.Trans, initial *chat.MessageJoin) error
if err != nil { return err }
defer this.leaveRoom(trans, room)
for {
message, err := chat.Receive(trans)
message, _, err := chat.Receive(trans)
if err != nil { return err }
switch message := message.(type) {
case *chat.MessageChat:
@@ -110,7 +111,7 @@ func (this *client) transTalk(trans hopp.Trans, initial *chat.MessageJoin) error
}
func (this *client) handleMessageChat(trans hopp.Trans, room string, message *chat.MessageChat) error {
log.Println("(). %s #%s: %s", this.nickname.Default("Anonymous"), room, message.Content)
log.Println("(). %s #%s: %s", this.nickname, room, message.Content)
clients, done := clients.RBorrow()
defer done()
for client := range clients {
@@ -126,7 +127,7 @@ func (this *client) relayMessage(room string, message *chat.MessageChat) error {
rooms, done := this.rooms.RBorrow()
defer done()
if trans, ok := rooms[room]; ok {
err := chat.Send(trans, message)
_, err := chat.Send(trans, message)
if err != nil {
return fmt.Errorf("could not relay message: %w", err)
}
@@ -141,7 +142,7 @@ func (this *client) joinRoom(trans hopp.Trans, room string) error {
return fmt.Errorf("already joined %s", room)
}
rooms[room] = trans
log.Printf("--> user %s joined #%s", this.nickname.Default("Anonymous"), room)
log.Printf("--> user %s joined #%s", this.nickname, room)
return nil
}
@@ -152,7 +153,7 @@ func (this *client) leaveRoom(trans hopp.Trans, room string) error {
return fmt.Errorf("not in %s", room)
}
delete(rooms, room)
log.Printf("<-- user %s left #%s", this.nickname.Default("Anonymous"), room)
log.Printf("<-- user %s left #%s", this.nickname, room)
return nil
}