|
Packit Service |
aa3af4 |
/*
|
|
Packit Service |
aa3af4 |
* Copyright (c) 2001-2020 Mellanox Technologies, Ltd. All rights reserved.
|
|
Packit Service |
aa3af4 |
*
|
|
Packit Service |
aa3af4 |
* This software is available to you under a choice of one of two
|
|
Packit Service |
aa3af4 |
* licenses. You may choose to be licensed under the terms of the GNU
|
|
Packit Service |
aa3af4 |
* General Public License (GPL) Version 2, available from the file
|
|
Packit Service |
aa3af4 |
* COPYING in the main directory of this source tree, or the
|
|
Packit Service |
aa3af4 |
* BSD license below:
|
|
Packit Service |
aa3af4 |
*
|
|
Packit Service |
aa3af4 |
* Redistribution and use in source and binary forms, with or
|
|
Packit Service |
aa3af4 |
* without modification, are permitted provided that the following
|
|
Packit Service |
aa3af4 |
* conditions are met:
|
|
Packit Service |
aa3af4 |
*
|
|
Packit Service |
aa3af4 |
* - Redistributions of source code must retain the above
|
|
Packit Service |
aa3af4 |
* copyright notice, this list of conditions and the following
|
|
Packit Service |
aa3af4 |
* disclaimer.
|
|
Packit Service |
aa3af4 |
*
|
|
Packit Service |
aa3af4 |
* - Redistributions in binary form must reproduce the above
|
|
Packit Service |
aa3af4 |
* copyright notice, this list of conditions and the following
|
|
Packit Service |
aa3af4 |
* disclaimer in the documentation and/or other materials
|
|
Packit Service |
aa3af4 |
* provided with the distribution.
|
|
Packit Service |
aa3af4 |
*
|
|
Packit Service |
aa3af4 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
Packit Service |
aa3af4 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
Packit Service |
aa3af4 |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
Packit Service |
aa3af4 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
Packit Service |
aa3af4 |
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
Packit Service |
aa3af4 |
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
Packit Service |
aa3af4 |
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
Packit Service |
aa3af4 |
* SOFTWARE.
|
|
Packit Service |
aa3af4 |
*/
|
|
Packit Service |
aa3af4 |
#ifndef __PEER_KEY_H__
|
|
Packit Service |
aa3af4 |
#define __PEER_KEY_H__
|
|
Packit Service |
aa3af4 |
|
|
Packit Service |
aa3af4 |
/**
|
|
Packit Service |
aa3af4 |
* Use union for representing ip:port as one uint64_t primitive,
|
|
Packit Service |
aa3af4 |
*
|
|
Packit Service |
aa3af4 |
* NOTE: this type provides implicit cast to uint64_t. Hence, it natively supports containers such as map and hash.
|
|
Packit Service |
aa3af4 |
*/
|
|
Packit Service |
aa3af4 |
union peer_key {
|
|
Packit Service |
aa3af4 |
public:
|
|
Packit Service |
aa3af4 |
peer_key(uint32_t _ip, uint16_t _port) : ip(_ip), port(_port){}
|
|
Packit Service |
aa3af4 |
operator uint64_t() const {return key;} // this saves the need for operator< and for operator== and for operator size_t() with map/hash
|
|
Packit Service |
aa3af4 |
|
|
Packit Service |
aa3af4 |
private:
|
|
Packit Service |
aa3af4 |
uint64_t key;
|
|
Packit Service |
aa3af4 |
|
|
Packit Service |
aa3af4 |
struct {
|
|
Packit Service |
aa3af4 |
uint32_t ip;
|
|
Packit Service |
aa3af4 |
uint32_t port; // 32 bits for making sure all bits of key are initialized
|
|
Packit Service |
aa3af4 |
};
|
|
Packit Service |
aa3af4 |
};
|
|
Packit Service |
aa3af4 |
|
|
Packit Service |
aa3af4 |
#endif /* ! __PEER_KEY_H__ */
|