---
title: llarp::NodeDB

---

# llarp::NodeDB





## Public Functions

|                | Name           |
| -------------- | -------------- |
| | **[NodeDB](Classes/classllarp_1_1NodeDB.md#function-nodedb)**(fs::path rootdir, std::function< void(std::function< void()>)> diskCaller) |
| | **[NodeDB](Classes/classllarp_1_1NodeDB.md#function-nodedb)**()<br>in memory nodedb  |
| void | **[LoadFromDisk](Classes/classllarp_1_1NodeDB.md#function-loadfromdisk)**()<br>load all entries from disk syncrhonously  |
| void | **[SaveToDisk](Classes/classllarp_1_1NodeDB.md#function-savetodisk)**() const<br>explicit save all RCs to disk synchronously  |
| size_t | **[NumLoaded](Classes/classllarp_1_1NodeDB.md#function-numloaded)**() const<br>the number of RCs that are loaded from disk  |
| void | **[Tick](Classes/classllarp_1_1NodeDB.md#function-tick)**(llarp_time_t now)<br>do periodic tasks like flush to disk and expiration  |
| [RouterContact](Classes/structllarp_1_1RouterContact.md) | **[FindClosestTo](Classes/classllarp_1_1NodeDB.md#function-findclosestto)**([dht::Key_t](Classes/structllarp_1_1dht_1_1Key__t.md) location) const<br>find the absolute closets router to a dht location  |
| std::vector< [RouterContact](Classes/structllarp_1_1RouterContact.md) > | **[FindManyClosestTo](Classes/classllarp_1_1NodeDB.md#function-findmanyclosestto)**([dht::Key_t](Classes/structllarp_1_1dht_1_1Key__t.md) location, uint32_t numRouters) const<br>find many routers closest to dht key  |
| bool | **[Has](Classes/classllarp_1_1NodeDB.md#function-has)**([RouterID](Classes/structllarp_1_1RouterID.md) pk) const<br>return true if we have an rc by its ident pubkey  |
| std::optional< [RouterContact](Classes/structllarp_1_1RouterContact.md) > | **[Get](Classes/classllarp_1_1NodeDB.md#function-get)**([RouterID](Classes/structllarp_1_1RouterID.md) pk) const<br>maybe get an rc by its ident pubkey  |
| template <typename Filter \> <br>std::optional< [RouterContact](Classes/structllarp_1_1RouterContact.md) > | **[GetRandom](Classes/classllarp_1_1NodeDB.md#function-getrandom)**(Filter visit) const |
| template <typename Visit \> <br>void | **[VisitAll](Classes/classllarp_1_1NodeDB.md#function-visitall)**(Visit visit) const<br>visit all entries  |
| template <typename Visit \> <br>void | **[VisitInsertedBefore](Classes/classllarp_1_1NodeDB.md#function-visitinsertedbefore)**(Visit visit, llarp_time_t insertedBefore)<br>visit all entries inserted before a timestamp  |
| void | **[Remove](Classes/classllarp_1_1NodeDB.md#function-remove)**([RouterID](Classes/structllarp_1_1RouterID.md) pk)<br>remove an entry via its ident pubkey  |
| template <typename Filter \> <br>void | **[RemoveIf](Classes/classllarp_1_1NodeDB.md#function-removeif)**(Filter visit)<br>remove an entry given a filter that inspects the rc  |
| void | **[RemoveStaleRCs](Classes/classllarp_1_1NodeDB.md#function-removestalercs)**(std::unordered_set< [RouterID](Classes/structllarp_1_1RouterID.md) > keep, llarp_time_t cutoff)<br>remove rcs that are not in keep and have been inserted before cutoff  |
| void | **[PutIfNewer](Classes/classllarp_1_1NodeDB.md#function-putifnewer)**([RouterContact](Classes/structllarp_1_1RouterContact.md) rc)<br>put this rc into the cache if it is not there or newer than the one there already  |
| void | **[Put](Classes/classllarp_1_1NodeDB.md#function-put)**([RouterContact](Classes/structllarp_1_1RouterContact.md) rc)<br>unconditional put of rc into cache  |

## Public Functions Documentation

### function NodeDB

```cpp
explicit NodeDB(
    fs::path rootdir,
    std::function< void(std::function< void()>)> diskCaller
)
```


### function NodeDB

```cpp
NodeDB()
```

in memory nodedb 

### function LoadFromDisk

```cpp
void LoadFromDisk()
```

load all entries from disk syncrhonously 

### function SaveToDisk

```cpp
void SaveToDisk() const
```

explicit save all RCs to disk synchronously 

### function NumLoaded

```cpp
size_t NumLoaded() const
```

the number of RCs that are loaded from disk 

### function Tick

```cpp
void Tick(
    llarp_time_t now
)
```

do periodic tasks like flush to disk and expiration 

### function FindClosestTo

```cpp
RouterContact FindClosestTo(
    dht::Key_t location
) const
```

find the absolute closets router to a dht location 

### function FindManyClosestTo

```cpp
std::vector< RouterContact > FindManyClosestTo(
    dht::Key_t location,
    uint32_t numRouters
) const
```

find many routers closest to dht key 

### function Has

```cpp
bool Has(
    RouterID pk
) const
```

return true if we have an rc by its ident pubkey 

### function Get

```cpp
std::optional< RouterContact > Get(
    RouterID pk
) const
```

maybe get an rc by its ident pubkey 

### function GetRandom

```cpp
template <typename Filter >
inline std::optional< RouterContact > GetRandom(
    Filter visit
) const
```


### function VisitAll

```cpp
template <typename Visit >
inline void VisitAll(
    Visit visit
) const
```

visit all entries 

### function VisitInsertedBefore

```cpp
template <typename Visit >
inline void VisitInsertedBefore(
    Visit visit,
    llarp_time_t insertedBefore
)
```

visit all entries inserted before a timestamp 

### function Remove

```cpp
void Remove(
    RouterID pk
)
```

remove an entry via its ident pubkey 

### function RemoveIf

```cpp
template <typename Filter >
inline void RemoveIf(
    Filter visit
)
```

remove an entry given a filter that inspects the rc 

### function RemoveStaleRCs

```cpp
void RemoveStaleRCs(
    std::unordered_set< RouterID > keep,
    llarp_time_t cutoff
)
```

remove rcs that are not in keep and have been inserted before cutoff 

### function PutIfNewer

```cpp
void PutIfNewer(
    RouterContact rc
)
```

put this rc into the cache if it is not there or newer than the one there already 

### function Put

```cpp
void Put(
    RouterContact rc
)
```

unconditional put of rc into cache 

-------------------------------

Updated on 2024-11-10 at 05:10:02 +0000