File: snid.c

package info (click to toggle)
ion 3.2.1%2Bdfsg-1.1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 23,768 kB
  • ctags: 11,049
  • sloc: ansic: 141,798; sh: 22,848; makefile: 7,818; python: 1,638; sql: 311; perl: 197; awk: 178; xml: 50; java: 19
file content (119 lines) | stat: -rw-r--r-- 2,393 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
 *	snid.c:		implementation of the extension definition
 *			functions for the Bundle Age Extension block.
 *
 *	Copyright (c) 2014, California Institute of Technology.
 *	ALL RIGHTS RESERVED.  U.S. Government Sponsorship
 *	acknowledged.
 *
 *	Author: Scott Burleigh, JPL
 */

#include "bpP.h"
#include "bei.h"
#include "snid.h"

int	snid_offer(ExtensionBlock *blk, Bundle *bundle)
{
	Sdnv	nodeNbrSdnv;
	char	dataBuffer[32];

	blk->blkProcFlags = BLK_MUST_BE_COPIED | BLK_REMOVE_IF_NG;
	encodeSdnv(&nodeNbrSdnv, getOwnNodeNbr());
	blk->dataLength = nodeNbrSdnv.length;
	blk->size = 0;
	blk->object = 0;
	memcpy(dataBuffer, nodeNbrSdnv.text, nodeNbrSdnv.length);
	return serializeExtBlk(blk, NULL, dataBuffer);
}

void	snid_release(ExtensionBlock *blk)
{
	return;
}

int	snid_record(ExtensionBlock *sdrBlk, AcqExtBlock *ramBlk)
{
	return 0;
}

int	snid_copy(ExtensionBlock *newBlk, ExtensionBlock *oldBlk)
{
	return 0;
}

int	snid_processOnFwd(ExtensionBlock *blk, Bundle *bundle, void *ctxt)
{
	return 0;
}

int	snid_processOnAccept(ExtensionBlock *blk, Bundle *bundle, void *ctxt)
{
	return 0;
}

int	snid_processOnEnqueue(ExtensionBlock *blk, Bundle *bundle, void *ctxt)
{
	return 0;
}

int	snid_processOnDequeue(ExtensionBlock *blk, Bundle *bundle, void *ctxt)
{
	return 0;
}

int	snid_acquire(AcqExtBlock *blk, AcqWorkArea *wk)
{
	uvast		senderNodeNbr;
	unsigned char	*cursor;
	int		bytesRemaining;
	char		uriBuffer[32];
	int		eidLen;

	if (blk->dataLength < 1)
	{
		return 0;		/*	Malformed.		*/
	}

	blk->size = 0;
	blk->object = NULL;

	/*	Sender ID from SNID block doesn't override sender ID
	 *	determined from other sources, such as PHN block.	*/

	if (wk->senderEid)		/*	Provided another way.	*/
	{
		return 1;		/*	Ignore SNID block.	*/
	}

	cursor = blk->bytes + (blk->length - blk->dataLength);
	bytesRemaining = blk->dataLength;
	extractSdnv(&senderNodeNbr, &cursor, &bytesRemaining);
	if (bytesRemaining != 0)
	{
		return 0;		/*	Malformed.		*/
	}

	eidLen = _isprintf(uriBuffer, sizeof uriBuffer,
			"ipn:" UVAST_FIELDSPEC ".0", senderNodeNbr) + 1;
	wk->senderEid = MTAKE(eidLen);
	if (wk->senderEid == NULL)
	{
		putErrmsg("Can't record sender EID.", NULL);
		return -1;
	}

	istrcpy(wk->senderEid, uriBuffer, eidLen);
	return 1;
}

int	snid_check(AcqExtBlock *blk, AcqWorkArea *wk)
{
	discardExtensionBlock(blk);
	return 0;
}

void	snid_clear(AcqExtBlock *blk)
{
	return;
}