commit 10e791f2ba95ac1efe927c988af78f6326f8ad80
parent a13a87be65103e61746d53e0be4e824db7a53423
Author: William Casarin <jb55@jb55.com>
Date: Wed, 7 Feb 2024 13:55:57 -0800
filters: copy filter metadata into subscription
This fixes a few ownership issues
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/src/nostrdb.c b/src/nostrdb.c
@@ -178,7 +178,7 @@ struct ndb_ingester {
};
struct ndb_filter_group {
- struct ndb_filter *filters[MAX_FILTERS];
+ struct ndb_filter filters[MAX_FILTERS];
int num_filters;
};
@@ -973,7 +973,7 @@ static int ndb_filter_group_add(struct ndb_filter_group *group,
if (group->num_filters + 1 > MAX_FILTERS)
return 0;
- group->filters[group->num_filters++] = filter;
+ memcpy(&group->filters[group->num_filters++], filter, sizeof(*filter));
return 1;
}
@@ -987,7 +987,7 @@ static int ndb_filter_group_matches(struct ndb_filter_group *group,
return 1;
for (i = 0; i < group->num_filters; i++) {
- filter = group->filters[i];
+ filter = &group->filters[i];
if (ndb_filter_matches(filter, note))
return 1;
@@ -3976,7 +3976,7 @@ void ndb_filter_group_destroy(struct ndb_filter_group *group)
struct ndb_filter *filter;
int i;
for (i = 0; i < group->num_filters; i++) {
- filter = group->filters[i];
+ filter = &group->filters[i];
ndb_filter_destroy(filter);
}
}
@@ -5664,10 +5664,8 @@ uint64_t ndb_subscribe(struct ndb *ndb, struct ndb_filter *filters, int num_filt
sub->subid = subid;
ndb_filter_group_init(&sub->group);
- for (index = 0; index < num_filters; index++) {
- if (!ndb_filter_group_add(&sub->group, &filters[index]))
- return 0;
- }
+ if (!ndb_filter_group_add_filters(&sub->group, filters, num_filters))
+ return 0;
// 500k ought to be enough for anyone
buflen = sizeof(uint64_t) * 65536;