Compare commits

..

No commits in common. "1b43b9268741aaa8aa0ed93d95efcdde0eb8b3f5" and "3daa66c4bceee6aaf45a5d533cb557cfaf5e3cee" have entirely different histories.

5 changed files with 25 additions and 33 deletions

View File

@ -1,11 +1,9 @@
package main
import "os"
import "io"
import "fmt"
import "time"
import "bufio"
import "errors"
import "context"
import "crypto/tls"
import "git.tebibyte.media/sashakoshka/hopp"
@ -24,7 +22,6 @@ func main() {
}
trans, err := join(address, room, nickname)
handleErr(1, err)
fmt.Fprintf(os.Stdout, "(i) connected to %s/%s\n", address, room)
go func() {
reader := bufio.NewReader(os.Stdin)
for {
@ -35,12 +32,7 @@ func main() {
}()
for {
message, _, err := chat.Receive(trans)
if err != nil {
if !errors.Is(err, io.EOF) {
handleErr(1, err)
}
break
}
handleErr(1, err)
switch message := message.(type) {
case *chat.MessageChat:
fmt.Fprintf(os.Stdout, "%s: %s\n", message.Nickname, message.Content)
@ -50,7 +42,6 @@ func main() {
fmt.Fprintf(os.Stdout, "(i) %s left the room\n", message.Nickname)
}
}
fmt.Fprintf(os.Stdout, "(i) disconnected\n")
}
func join(address string, room string, nickname string) (hopp.Trans, error) {

View File

@ -1,7 +1,6 @@
package main
import "os"
import "io"
import "fmt"
import "log"
import "errors"
@ -49,7 +48,7 @@ func host(address string, certPath, keyPath string) error {
type client struct {
conn hopp.Conn
nickname string
nickname hopp.Option[string]
rooms usync.RWMonitor[map[string] hopp.Trans]
}
@ -59,13 +58,13 @@ func (this *client) run() {
defer this.conn.Close()
for {
log.Println("accepting transaction")
trans, err := this.conn.AcceptTrans()
if err != nil {
if !errors.Is(err, io.EOF) {
log.Printf("XXX %v failed: %v", this.conn.RemoteAddr(), err)
}
log.Printf("XXX %v failed: %v", this.conn.RemoteAddr(), err)
return
}
log.Println("accepted transaction")
go this.runTrans(trans)
}
}
@ -112,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.Printf("(). %s #%s: %s", this.nickname, room, message.Content)
log.Println("(). %s #%s: %s", this.nickname, room, message.Content)
clients, done := clients.RBorrow()
defer done()
for client := range clients {

View File

@ -1237,9 +1237,7 @@ func (this *Generator) generateReceive() (n int, err error) {
}
nn, err = this.iprint("}\n")
n += nn; if err != nil { return n, err }
// fuck off go vet
str := `return nil, n, fmt.Errorf("%w: M%04X", hopp.ErrUnknownMethod, method)`
nn, err = this.iprintln(str)
nn, err = this.iprint("return nil, n, fmt.Errorf(\"%w: M%04X\", hopp.ErrUnknownMethod, method)\n")
n += nn; if err != nil { return n, err }
this.pop()
nn, err = this.iprint("}\n")

View File

@ -6,7 +6,6 @@ import "fmt"
import "net"
import "sync"
import "time"
import "context"
import "sync/atomic"
import "git.tebibyte.media/sashakoshka/go-util/sync"
@ -40,23 +39,20 @@ type a struct {
sendLock sync.Mutex
transMap map[int64] *transA
transChan chan *transA
ctx context.Context
done func()
done chan struct { }
err error
}
// AdaptA returns a connection implementing METADAPT-A over a singular stream-
// oriented transport such as TCP or UNIX domain stream sockets.
func AdaptA(underlying net.Conn, party Party) Conn {
ctx, done := context.WithCancel(context.Background())
conn := &a {
sizeLimit: defaultSizeLimit,
underlying: underlying,
party: party,
transMap: make(map[int64] *transA),
transChan: make(chan *transA),
ctx: ctx,
done: done,
done: make(chan struct { }),
}
if party == ClientSide {
conn.transID = 1
@ -64,15 +60,11 @@ func AdaptA(underlying net.Conn, party Party) Conn {
conn.transID = -1
}
go conn.receive()
go func() {
<- ctx.Done()
underlying.Close()
}()
return conn
}
func (this *a) Close() error {
this.done()
close(this.done)
return nil
}
@ -113,7 +105,7 @@ func (this *a) AcceptTrans() (Trans, error) {
return nil, eof
}
return trans, nil
case <- this.ctx.Done():
case <- this.done:
return nil, eof
}
}
@ -498,7 +490,6 @@ func decodeMessageA(
headerBuffer := [18]byte { }
_, err = io.ReadFull(reader, headerBuffer[:])
if err != nil { return 0, 0, false, nil, err }
transID, err = decodeI64[int64](headerBuffer[:8])
if err != nil { return 0, 0, false, nil, err }
method, err = decodeI16[uint16](headerBuffer[8:10])

View File

@ -52,7 +52,6 @@ func TestConnA(test *testing.T) {
test.Error("CLIENT payload:", gotPayload)
test.Fatal("CLIENT ok byeeeeeeeeeeeee")
}
test.Log("CLIENT transaction has closed")
}
serverFunc := func(a Conn) {
@ -71,6 +70,20 @@ func TestConnA(test *testing.T) {
}
func TestTransOpenCloseA(test *testing.T) {
// currently:
//
// | data sent | data recvd | close sent | close recvd
// 10 | X | X | X | server hangs
// 20 | X | X | X | client hangs
// 30 | X | | X |
//
// when a close message is recvd, it tries to push to the trans and
// hangs on trans.incoming.Send, which hangs on sending the value to the
// underlying channel. why is this?
//
// check if we are really getting values from the channel when pulling
// from the trans channel when we are expecting a close.
clientFunc := func(conn Conn) {
// 10
trans, err := conn.OpenTrans()