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() {
this.underlying.Close()
this.transLock.Lock()
defer this.transLock.Lock()
defer this.transLock.Unlock()
for _, trans := range this.transMap {
trans.Close()
}
@ -124,22 +124,30 @@ func (this *a) receive() {
}
func (this *a) receiveMultiplex(transID int64, method uint16, payload []byte) error {
if transID == 0 || this.party == partyFromTransID(transID) {
return ErrMessageMalformed
}
this.transLock.Lock()
defer this.transLock.Unlock()
if transID == 0 { return ErrMessageMalformed }
trans, ok := this.transMap[transID]
if !ok {
trans = &transA {
parent: this,
id: transID,
incoming: usync.NewGate[incomingMessage](),
trans, err := func() (*transA, error) {
this.transLock.Lock()
defer this.transLock.Unlock()
trans, ok := this.transMap[transID]
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 {
method: method,