forked from ElementsProject/lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
common: move gossip_store read routine where subdaemons can access it.
Signed-off-by: Rusty Russell <[email protected]>
- Loading branch information
1 parent
d8db4e8
commit 0e37ac2
Showing
12 changed files
with
79 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include <ccan/crc/crc.h> | ||
#include <ccan/endian/endian.h> | ||
#include <common/gossip_store.h> | ||
#include <common/status.h> | ||
#include <errno.h> | ||
#include <inttypes.h> | ||
#include <unistd.h> | ||
|
||
u8 *gossip_store_read(const tal_t *ctx, int gossip_store_fd, u64 offset) | ||
{ | ||
beint32_t hdr[2]; | ||
u32 msglen, checksum; | ||
u8 *msg; | ||
|
||
if (offset == 0) | ||
status_failed(STATUS_FAIL_INTERNAL_ERROR, | ||
"gossip_store: can't access offset %"PRIu64, | ||
offset); | ||
if (pread(gossip_store_fd, hdr, sizeof(hdr), offset) != sizeof(hdr)) { | ||
status_failed(STATUS_FAIL_INTERNAL_ERROR, | ||
"gossip_store: can't read hdr offset %"PRIu64 | ||
": %s", | ||
offset, strerror(errno)); | ||
} | ||
|
||
msglen = be32_to_cpu(hdr[0]); | ||
checksum = be32_to_cpu(hdr[1]); | ||
msg = tal_arr(ctx, u8, msglen); | ||
if (pread(gossip_store_fd, msg, msglen, offset + sizeof(hdr)) != msglen) | ||
status_failed(STATUS_FAIL_INTERNAL_ERROR, | ||
"gossip_store: can't read len %u offset %"PRIu64, | ||
msglen, offset); | ||
|
||
if (checksum != crc32c(0, msg, msglen)) | ||
status_failed(STATUS_FAIL_INTERNAL_ERROR, | ||
"gossip_store: bad checksum offset %"PRIu64, | ||
offset); | ||
|
||
return msg; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef LIGHTNING_COMMON_GOSSIP_STORE_H | ||
#define LIGHTNING_COMMON_GOSSIP_STORE_H | ||
#include "config.h" | ||
#include <ccan/short_types/short_types.h> | ||
#include <ccan/tal/tal.h> | ||
|
||
/** | ||
* gossip_store -- On-disk storage related information | ||
*/ | ||
#define GOSSIP_STORE_VERSION 4 | ||
|
||
/** | ||
* Direct store accessor: loads gossip msg from store. | ||
* | ||
* Doesn't return; status_failed() on error. | ||
*/ | ||
u8 *gossip_store_read(const tal_t *ctx, int gossip_store_fd, u64 offset); | ||
|
||
#endif /* LIGHTNING_COMMON_GOSSIP_STORE_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters