Fix METADAPT-A not receiving more than one message

This commit is contained in:
Sasha Koshka 2025-01-26 00:26:12 -05:00
parent 659bcecbe6
commit 5e885a0bd3

View File

@ -102,7 +102,7 @@ func (this *a) receive() {
defer func() { defer func() {
this.underlying.Close() this.underlying.Close()
this.transLock.Lock() this.transLock.Lock()
defer this.transLock.Lock() defer this.transLock.Unlock()
for _, trans := range this.transMap { for _, trans := range this.transMap {
trans.Close() trans.Close()
} }
@ -124,22 +124,30 @@ func (this *a) receive() {
} }
func (this *a) receiveMultiplex(transID int64, method uint16, payload []byte) error { func (this *a) receiveMultiplex(transID int64, method uint16, payload []byte) error {
if transID == 0 || this.party == partyFromTransID(transID) { if transID == 0 { return ErrMessageMalformed }
return ErrMessageMalformed
}
this.transLock.Lock()
defer this.transLock.Unlock()
trans, ok := this.transMap[transID] trans, err := func() (*transA, error) {
if !ok { this.transLock.Lock()
trans = &transA { defer this.transLock.Unlock()
parent: this,
id: transID, trans, ok := this.transMap[transID]
incoming: usync.NewGate[incomingMessage](), if !ok {
// it is forbidden for the other party to initiate a transaction
// with an ID from this party
if this.party == partyFromTransID(transID) {
return nil, ErrMessageMalformed
}
trans = &transA {
parent: this,
id: transID,
incoming: usync.NewGate[incomingMessage](),
}
this.transMap[transID] = trans
this.transChan <- trans
} }
this.transChan <- trans return trans, nil
} }()
if err != nil { return err }
trans.incoming.Send(incomingMessage { trans.incoming.Send(incomingMessage {
method: method, method: method,