Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
libloc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
libloc
Commits
233311e8
Commit
233311e8
authored
Mar 09, 2022
by
Michael Tremer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
writer: Use AS list internally
Signed-off-by:
Michael Tremer
<
michael.tremer@ipfire.org
>
parent
f13c23b7
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
36 deletions
+47
-36
src/as-list.c
src/as-list.c
+9
-0
src/libloc.sym
src/libloc.sym
+1
-0
src/libloc/as-list.h
src/libloc/as-list.h
+2
-0
src/writer.c
src/writer.c
+35
-36
No files found.
src/as-list.c
View file @
233311e8
...
...
@@ -163,3 +163,12 @@ LOC_EXPORT int loc_as_list_contains_number(
return
r
;
}
static
int
__loc_as_cmp
(
const
void
*
as1
,
const
void
*
as2
)
{
return
loc_as_cmp
(
*
(
struct
loc_as
**
)
as1
,
*
(
struct
loc_as
**
)
as2
);
}
LOC_EXPORT
void
loc_as_list_sort
(
struct
loc_as_list
*
list
)
{
// Sort everything
qsort
(
list
->
elements
,
list
->
size
,
sizeof
(
*
list
->
elements
),
__loc_as_cmp
);
}
src/libloc.sym
View file @
233311e8
...
...
@@ -27,6 +27,7 @@ global:
loc_as_list_new;
loc_as_list_ref;
loc_as_list_size;
loc_as_list_sort;
loc_as_list_unref;
# Country
...
...
src/libloc/as-list.h
View file @
233311e8
...
...
@@ -38,4 +38,6 @@ int loc_as_list_contains(
int
loc_as_list_contains_number
(
struct
loc_as_list
*
list
,
uint32_t
number
);
void
loc_as_list_sort
(
struct
loc_as_list
*
list
);
#endif
src/writer.c
View file @
233311e8
...
...
@@ -33,6 +33,7 @@
#include <libloc/libloc.h>
#include <libloc/as.h>
#include <libloc/as-list.h>
#include <libloc/compat.h>
#include <libloc/country.h>
#include <libloc/database.h>
...
...
@@ -60,13 +61,12 @@ struct loc_writer {
char
signature2
[
LOC_SIGNATURE_MAX_LENGTH
];
size_t
signature2_length
;
struct
loc_as
**
as
;
size_t
as_count
;
struct
loc_country
**
countries
;
size_t
countries_count
;
struct
loc_network_tree
*
networks
;
struct
loc_as_list
*
as_list
;
};
static
int
parse_private_key
(
struct
loc_writer
*
writer
,
EVP_PKEY
**
private_key
,
FILE
*
f
)
{
...
...
@@ -110,6 +110,13 @@ LOC_EXPORT int loc_writer_new(struct loc_ctx* ctx, struct loc_writer** writer,
return
r
;
}
// Initialize AS list
r
=
loc_as_list_new
(
ctx
,
&
w
->
as_list
);
if
(
r
)
{
loc_writer_unref
(
w
);
return
r
;
}
// Load the private keys to sign databases
if
(
fkey1
)
{
r
=
parse_private_key
(
w
,
&
w
->
private_key1
,
fkey1
);
...
...
@@ -147,12 +154,8 @@ static void loc_writer_free(struct loc_writer* writer) {
EVP_PKEY_free
(
writer
->
private_key2
);
// Unref all AS
if
(
writer
->
as
)
{
for
(
unsigned
int
i
=
0
;
i
<
writer
->
as_count
;
i
++
)
{
loc_as_unref
(
writer
->
as
[
i
]);
}
free
(
writer
->
as
);
}
if
(
writer
->
as_list
)
loc_as_list_unref
(
writer
->
as_list
);
// Unref all countries
if
(
writer
->
countries
)
{
...
...
@@ -224,30 +227,14 @@ LOC_EXPORT int loc_writer_set_license(struct loc_writer* writer, const char* lic
return
0
;
}
static
int
__loc_as_cmp
(
const
void
*
as1
,
const
void
*
as2
)
{
return
loc_as_cmp
(
*
(
struct
loc_as
**
)
as1
,
*
(
struct
loc_as
**
)
as2
);
}
LOC_EXPORT
int
loc_writer_add_as
(
struct
loc_writer
*
writer
,
struct
loc_as
**
as
,
uint32_t
number
)
{
// Create a new AS object
int
r
=
loc_as_new
(
writer
->
ctx
,
as
,
number
);
if
(
r
)
return
r
;
// We have a new AS to add
writer
->
as_count
++
;
// Make space
writer
->
as
=
realloc
(
writer
->
as
,
sizeof
(
*
writer
->
as
)
*
writer
->
as_count
);
if
(
!
writer
->
as
)
return
-
ENOMEM
;
// Add as last element
writer
->
as
[
writer
->
as_count
-
1
]
=
loc_as_ref
(
*
as
);
// Sort everything
qsort
(
writer
->
as
,
writer
->
as_count
,
sizeof
(
*
writer
->
as
),
__loc_as_cmp
);
return
0
;
// Append it to the list
return
loc_as_list_append
(
writer
->
as_list
,
*
as
);
}
LOC_EXPORT
int
loc_writer_add_network
(
struct
loc_writer
*
writer
,
struct
loc_network
**
network
,
const
char
*
string
)
{
...
...
@@ -325,20 +312,32 @@ static int loc_database_write_as_section(struct loc_writer* writer,
DEBUG
(
writer
->
ctx
,
"AS section starts at %jd bytes
\n
"
,
(
intmax_t
)
*
offset
);
header
->
as_offset
=
htobe32
(
*
offset
);
size_t
as_length
=
0
;
// Sort the AS list first
loc_as_list_sort
(
writer
->
as_list
);
const
size_t
as_count
=
loc_as_list_size
(
writer
->
as_list
);
struct
loc_database_as_v1
block
;
size_t
block_length
=
0
;
for
(
unsigned
int
i
=
0
;
i
<
as_count
;
i
++
)
{
struct
loc_as
*
as
=
loc_as_list_get
(
writer
->
as_list
,
i
);
if
(
!
as
)
return
1
;
struct
loc_database_as_v1
as
;
for
(
unsigned
int
i
=
0
;
i
<
writer
->
as_count
;
i
++
)
{
// Convert AS into database format
loc_as_to_database_v1
(
writer
->
as
[
i
],
writer
->
pool
,
&
as
);
loc_as_to_database_v1
(
as
,
writer
->
pool
,
&
block
);
// Write to disk
*
offset
+=
fwrite
(
&
as
,
1
,
sizeof
(
as
),
f
);
as_length
+=
sizeof
(
as
);
*
offset
+=
fwrite
(
&
block
,
1
,
sizeof
(
block
),
f
);
block_length
+=
sizeof
(
block
);
// Unref AS
loc_as_unref
(
as
);
}
DEBUG
(
writer
->
ctx
,
"AS section has a length of %zu bytes
\n
"
,
as
_length
);
header
->
as_length
=
htobe32
(
as
_length
);
DEBUG
(
writer
->
ctx
,
"AS section has a length of %zu bytes
\n
"
,
block
_length
);
header
->
as_length
=
htobe32
(
block
_length
);
align_page_boundary
(
offset
,
f
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment