@@ -102,21 +102,13 @@ void Interface::Disable(void)
102102 VerifyOrExit (mInitialized );
103103
104104 otPlatTrelDisable (&GetInstance ());
105- ClearPeerList ();
105+ Get<PeerTable>(). Clear ();
106106 LogDebg (" Disabled interface" );
107107
108108exit:
109109 return ;
110110}
111111
112- void Interface::ClearPeerList (void )
113- {
114- mPeerList .Clear ();
115- mPeerPool .FreeAll ();
116- }
117-
118- Peer *Interface::FindPeer (const Mac::ExtAddress &aExtAddress) { return mPeerList .FindMatching (aExtAddress); }
119-
120112void Interface::NotifyPeerSocketAddressDifference (const Ip6::SockAddr &aPeerSockAddr, const Ip6::SockAddr &aRxSockAddr)
121113{
122114 otPlatTrelNotifyPeerSocketAddressDifference (&GetInstance (), &aPeerSockAddr, &aRxSockAddr);
@@ -183,7 +175,7 @@ extern "C" void otPlatTrelHandleDiscoveredPeerInfo(otInstance *aInstance, const
183175
184176void Interface::HandleDiscoveredPeerInfo (const PeerInfo &aInfo)
185177{
186- Peer *entry ;
178+ Peer *peer ;
187179 Mac::ExtAddress extAddress;
188180 MeshCoP::ExtendedPanId extPanId;
189181 bool isNew = false ;
@@ -196,9 +188,7 @@ void Interface::HandleDiscoveredPeerInfo(const PeerInfo &aInfo)
196188
197189 if (aInfo.IsRemoved ())
198190 {
199- entry = FindPeer (extAddress);
200- VerifyOrExit (entry != nullptr );
201- RemovePeerEntry (*entry);
191+ Get<PeerTable>().RemoveAndFreeAllMatching (extAddress);
202192 ExitNow ();
203193 }
204194
@@ -208,37 +198,37 @@ void Interface::HandleDiscoveredPeerInfo(const PeerInfo &aInfo)
208198 // different Extended MAC address. This ensures that we do not
209199 // keep stale entries in the peer table.
210200
211- entry = mPeerList .FindMatching (aInfo.GetSockAddr ());
201+ peer = Get<PeerTable>() .FindMatching (aInfo.GetSockAddr ());
212202
213- if ((entry != nullptr ) && !entry ->Matches (extAddress))
203+ if ((peer != nullptr ) && !peer ->Matches (extAddress))
214204 {
215- RemovePeerEntry (*entry );
216- entry = nullptr ;
205+ Get<PeerTable>(). RemoveMatching (aInfo. GetSockAddr () );
206+ peer = nullptr ;
217207 }
218208
219- if (entry == nullptr )
209+ if (peer == nullptr )
220210 {
221- entry = mPeerList .FindMatching (extAddress);
211+ peer = Get<PeerTable>() .FindMatching (extAddress);
222212 }
223213
224- if (entry == nullptr )
214+ if (peer == nullptr )
225215 {
226- entry = GetNewPeerEntry ();
227- VerifyOrExit (entry != nullptr );
216+ peer = Get<PeerTable>(). AllocateAndAddNewPeer ();
217+ VerifyOrExit (peer != nullptr );
228218
229- entry ->SetExtAddress (extAddress);
219+ peer ->SetExtAddress (extAddress);
230220 isNew = true ;
231221 }
232222
233223 if (!isNew)
234224 {
235- VerifyOrExit ((entry ->GetExtPanId () != extPanId) || (entry ->GetSockAddr () != aInfo.GetSockAddr ()));
225+ VerifyOrExit ((peer ->GetExtPanId () != extPanId) || (peer ->GetSockAddr () != aInfo.GetSockAddr ()));
236226 }
237227
238- entry ->SetExtPanId (extPanId);
239- entry ->SetSockAddr (aInfo.GetSockAddr ());
228+ peer ->SetExtPanId (extPanId);
229+ peer ->SetSockAddr (aInfo.GetSockAddr ());
240230
241- entry ->Log (isNew ? Peer::kAdded : Peer::kUpdated );
231+ peer ->Log (isNew ? Peer::kAdded : Peer::kUpdated );
242232
243233exit:
244234 return ;
@@ -294,60 +284,6 @@ Error Interface::PeerInfo::ParseTxtData(Mac::ExtAddress &aExtAddress, MeshCoP::E
294284 return error;
295285}
296286
297- Peer *Interface::GetNewPeerEntry (void )
298- {
299- Peer *peerEntry;
300-
301- peerEntry = mPeerPool .Allocate ();
302-
303- if (peerEntry != nullptr )
304- {
305- mPeerList .Push (*peerEntry);
306- ExitNow ();
307- }
308-
309- for (Peer &entry : mPeerList )
310- {
311- if (entry.GetExtPanId () != Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId ())
312- {
313- ExitNow (peerEntry = &entry);
314- }
315- }
316-
317- for (Peer &entry : mPeerList )
318- {
319- // We skip over any existing entry in neighbor table (even if the
320- // entry is in invalid state).
321-
322- if (Get<NeighborTable>().FindNeighbor (entry.GetExtAddress (), Neighbor::kInStateAny ) != nullptr )
323- {
324- continue ;
325- }
326-
327- #if OPENTHREAD_FTD
328- if (Get<NeighborTable>().FindRxOnlyNeighborRouter (entry.GetExtAddress ()) != nullptr )
329- {
330- continue ;
331- }
332- #endif
333-
334- ExitNow (peerEntry = &entry);
335- }
336-
337- exit:
338- return peerEntry;
339- }
340-
341- void Interface::RemovePeerEntry (Peer &aEntry)
342- {
343- aEntry.Log (Peer::kRemoving );
344-
345- if (mPeerList .Remove (aEntry) == kErrorNone )
346- {
347- mPeerPool .Free (aEntry);
348- }
349- }
350-
351287const Counters *Interface::GetCounters (void ) const { return otPlatTrelGetCounters (&GetInstance ()); }
352288
353289void Interface::ResetCounters (void ) { otPlatTrelResetCounters (&GetInstance ()); }
@@ -363,20 +299,20 @@ Error Interface::Send(const Packet &aPacket, bool aIsDiscovery)
363299 switch (aPacket.GetHeader ().GetType ())
364300 {
365301 case Header::kTypeBroadcast :
366- for (Peer &entry : mPeerList )
302+ for (const Peer &peer : Get<PeerTable>() )
367303 {
368- if (!aIsDiscovery && (entry .GetExtPanId () != Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId ()))
304+ if (!aIsDiscovery && (peer .GetExtPanId () != Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId ()))
369305 {
370306 continue ;
371307 }
372308
373- otPlatTrelSend (&GetInstance (), aPacket.GetBuffer (), aPacket.GetLength (), &entry .mSockAddr );
309+ otPlatTrelSend (&GetInstance (), aPacket.GetBuffer (), aPacket.GetLength (), &peer .mSockAddr );
374310 }
375311 break ;
376312
377313 case Header::kTypeUnicast :
378314 case Header::kTypeAck :
379- peerEntry = mPeerList .FindMatching (aPacket.GetHeader ().GetDestination ());
315+ peerEntry = Get<PeerTable>() .FindMatching (aPacket.GetHeader ().GetDestination ());
380316 VerifyOrExit (peerEntry != nullptr , error = kErrorAbort );
381317 otPlatTrelSend (&GetInstance (), aPacket.GetBuffer (), aPacket.GetLength (), &peerEntry->mSockAddr );
382318 break ;
@@ -413,30 +349,6 @@ void Interface::HandleReceived(uint8_t *aBuffer, uint16_t aLength, const Ip6::So
413349 return ;
414350}
415351
416- const Peer *Interface::GetNextPeer (PeerIterator &aIterator) const
417- {
418- const Peer *entry = static_cast <const Peer *>(aIterator);
419-
420- VerifyOrExit (entry != nullptr );
421- aIterator = entry->GetNext ();
422-
423- exit:
424- return entry;
425- }
426-
427- uint16_t Interface::GetNumberOfPeers (void ) const
428- {
429- uint16_t count = 0 ;
430-
431- for (const Peer &peer : mPeerList )
432- {
433- OT_UNUSED_VARIABLE (peer);
434- count++;
435- }
436-
437- return count;
438- }
439-
440352} // namespace Trel
441353} // namespace ot
442354
0 commit comments