Browse Source
I really want a type which means "I am a wrapped onion reply" as separate from "I am a normal wire msg". Currently both user u8 *, and I got very confused trying to figure out where each one was an unwrapped error msg, or where it still needed (un)wrapping. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>travis-debug
Rusty Russell
5 years ago
6 changed files with 88 additions and 0 deletions
@ -0,0 +1,40 @@ |
|||
#include <ccan/cast/cast.h> |
|||
#include <common/onionreply.h> |
|||
#include <wire/wire.h> |
|||
|
|||
void towire_onionreply(u8 **cursor, const struct onionreply *r) |
|||
{ |
|||
towire_u16(cursor, tal_count(r->contents)); |
|||
towire_u8_array(cursor, r->contents, tal_count(r->contents)); |
|||
} |
|||
|
|||
struct onionreply *fromwire_onionreply(const tal_t *ctx, |
|||
const u8 **cursor, size_t *max) |
|||
{ |
|||
struct onionreply *r = tal(ctx, struct onionreply); |
|||
r->contents = tal_arr(r, u8, fromwire_u16(cursor, max)); |
|||
fromwire_u8_array(cursor, max, r->contents, tal_count(r->contents)); |
|||
if (!*cursor) |
|||
return tal_free(r); |
|||
return r; |
|||
} |
|||
|
|||
struct onionreply *dup_onionreply(const tal_t *ctx, |
|||
const struct onionreply *r TAKES) |
|||
{ |
|||
struct onionreply *n; |
|||
|
|||
if (taken(r)) |
|||
return cast_const(struct onionreply *, tal_steal(ctx, r)); |
|||
|
|||
n = tal(ctx, struct onionreply); |
|||
n->contents = tal_dup_arr(n, u8, r->contents, tal_count(r->contents), 0); |
|||
return n; |
|||
} |
|||
|
|||
struct onionreply *new_onionreply(const tal_t *ctx, const u8 *contents TAKES) |
|||
{ |
|||
struct onionreply *r = tal(ctx, struct onionreply); |
|||
r->contents = tal_dup_arr(r, u8, contents, tal_count(contents), 0); |
|||
return r; |
|||
} |
@ -0,0 +1,24 @@ |
|||
#ifndef LIGHTNING_COMMON_ONIONREPLY_H |
|||
#define LIGHTNING_COMMON_ONIONREPLY_H |
|||
#include "config.h" |
|||
#include <ccan/short_types/short_types.h> |
|||
#include <ccan/tal/tal.h> |
|||
|
|||
/* A separate type for an onion reply, to differentiate from a wire msg. */ |
|||
struct onionreply { |
|||
u8 *contents; |
|||
}; |
|||
|
|||
/**
|
|||
* Wire marshalling routines for onionreply |
|||
*/ |
|||
void towire_onionreply(u8 **cursor, const struct onionreply *r); |
|||
struct onionreply *fromwire_onionreply(const tal_t *ctx, |
|||
const u8 **cursor, size_t *max); |
|||
|
|||
|
|||
struct onionreply *dup_onionreply(const tal_t *ctx, |
|||
const struct onionreply *r TAKES); |
|||
|
|||
struct onionreply *new_onionreply(const tal_t *ctx, const u8 *contents TAKES); |
|||
#endif /* LIGHTNING_COMMON_ONIONREPLY_H */ |
Loading…
Reference in new issue