sendEDU adds the EDU event to the pending queue for the destination. If the queue is empty then it starts a background goroutine to start sending events to that destination.
(event *gomatrixserverlib.EDU, receipt *shared.Receipt)
| 115 | // If the queue is empty then it starts a background goroutine to |
| 116 | // start sending events to that destination. |
| 117 | func (oq *destinationQueue) sendEDU(event *gomatrixserverlib.EDU, receipt *shared.Receipt) { |
| 118 | if event == nil { |
| 119 | logrus.Errorf("attempt to send nil EDU with destination %q", oq.destination) |
| 120 | return |
| 121 | } |
| 122 | // Create a database entry that associates the given PDU NID with |
| 123 | // this destination queue. We'll then be able to retrieve the PDU |
| 124 | // later. |
| 125 | if err := oq.db.AssociateEDUWithDestination( |
| 126 | oq.process.Context(), |
| 127 | oq.destination, // the destination server name |
| 128 | receipt, // NIDs from federationapi_queue_json table |
| 129 | event.Type, |
| 130 | nil, // this will use the default expireEDUTypes map |
| 131 | ); err != nil { |
| 132 | logrus.WithError(err).Errorf("failed to associate EDU with destination %q", oq.destination) |
| 133 | return |
| 134 | } |
| 135 | // Check if the destination is blacklisted. If it isn't then wake |
| 136 | // up the queue. |
| 137 | if !oq.statistics.Blacklisted() { |
| 138 | // If there's room in memory to hold the event then add it to the |
| 139 | // list. |
| 140 | oq.pendingMutex.Lock() |
| 141 | if len(oq.pendingEDUs) < maxEDUsInMemory { |
| 142 | oq.pendingEDUs = append(oq.pendingEDUs, &queuedEDU{ |
| 143 | edu: event, |
| 144 | receipt: receipt, |
| 145 | }) |
| 146 | } else { |
| 147 | oq.overflowed.Store(true) |
| 148 | } |
| 149 | oq.pendingMutex.Unlock() |
| 150 | // Wake up the queue if it's asleep. |
| 151 | oq.wakeQueueIfNeeded() |
| 152 | select { |
| 153 | case oq.notify <- struct{}{}: |
| 154 | default: |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | // wakeQueueIfNeeded will wake up the destination queue if it is |
| 160 | // not already running. If it is running but it is backing off |
no test coverage detected