Statistics
| Branch: | Revision:

pstreamer / src / peer_metadata.c @ dc99f5c4

History | View | Annotate | Download (1.52 KB)

1
/*
2
 * Copyright (c) 2017 Luca Baldesi
3
 *
4
 * This file is part of PeerStreamer.
5
 *
6
 * PeerStreamer is free software: you can redistribute it and/or
7
 * modify it under the terms of the GNU Affero General Public License as
8
 * published by the Free Software Foundation, either version 3 of the
9
 * License, or (at your option) any later version.
10
 *
11
 * PeerStreamer is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero
14
 * General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Affero General Public License
17
 * along with PeerStreamer.  If not, see <http://www.gnu.org/licenses/>.
18
 *
19
 */
20

    
21
#include<peer_metadata.h>
22
#include<malloc.h>
23
#include<string.h>
24

    
25
int8_t metadata_update(struct metadata *m, uint16_t cb_size, uint8_t neigh_size)
26
{
27
        if (m)
28
        {
29
                m->cb_size = cb_size;
30
                m->neigh_size = neigh_size;
31
                return 0;
32
        }
33
        return -1;
34
}
35

    
36
int8_t peer_set_metadata(struct  peer *p, const struct metadata *m)
37
{
38
        if (p && m)
39
        {
40
                if (!(p->metadata))
41
                        p->metadata = malloc(sizeof(struct metadata));
42
                memmove(p->metadata, m, sizeof(struct metadata));
43
                return 0;
44
        }
45
        return -1;
46
}
47

    
48
uint16_t peer_cb_size(const struct peer *p)
49
{
50
        if (p && p->metadata)
51
                return ((struct metadata *)p->metadata)->cb_size;
52
        return DEFAULT_PEER_CBSIZE;
53
}
54

    
55
uint16_t peer_neigh_size(const struct peer *p)
56
{
57
        if (p && p->metadata)
58
                return ((struct metadata *)p->metadata)->neigh_size;
59
        return DEFAULT_PEER_NEIGH_SIZE;
60
}