The Cellframe.Network module is designed to work with network. This module includes the following classes:
CellFrame.Network.Node
A class represents a node.CellFrame.Network.NodeInfo
A class represents node information.CellFrame.Network.NodeClient
A class represents node client.CellFrame.Network.NodeAddr
A class represents node address.CellFrame.Network.Net
A class represents a net.CellFrame.Network.NetID
A class represents a net identificator.CellFrame.Network.NetState
A class represents a net state.CellFrame.Network.Service
A class represents a service.CellFrame.Network.ServiceClient
A class represents a service.CellFrame.Network.ServicePrice
A class represents a service price.CellFrame.Network.ServiceOrder
A class represents a service order.CellFrame.Network.ServiceOrderDirection
A class represents a service order direction.CellFrame.Network.ServiceUID
A class represents a service unique identificator.CellFrame.Network.ServicePriceUnitUID
A class represents a service price unit unique identificator.class CellFrame.Network.Node
This class representes the node object.
static method CellFrame.Network.Node.genAddr(chainNet: CellFrame.Network.Net, cellId: CellFrame.Chain.ChainCellID) -> CellFrame.Network.NodeAddr
Generates a node address by the cellId
. Returns NodeAddr
object if successful.
static method CellFrame.Network.Node.checkAddr(chainNet: CellFrame.Network.Net, nodeAddress: CellFrame.Network.NodeAddr, cellId: CellFrame.Chain.ChainCellID) -> bool
Checks the validity of the nodeAddress
by the cellId
. Returns True
if successful otherwise False
.
static method CellFrame.Network.Node.aliasFind(chainNet: CellFrame.Network.Net, alias: str) -> CellFrame.Network.NodeAddr
Finds a node address by the alias
frome a database. Returns NodeAddr
object if successful.
static method CellFrame.Network.Node.aliasRegister(chainNet: CellFrame.Network.Net, alias: str, address: CellFrame.Network.NodeAddr) -> bool
Registers the alias
for the address
in a database. Returns True
if successful, otherwise False
.
static method CellFrame.Network.Node.aliasDelete(chainNet: CellFrame.Network.Net, alias: str) -> bool
Deletes the alias
in a database. Returns True
if successful, otherwise False
.
class CellFrame.Network.NodeInfo
This class provides methods for working with a node informations.
object method CellFrame.Network.NodeInfo.save(chainNet: CellFrame.Network.Net) -> int
Saves a node information to a database. Returns 0
if successful, otherwise error code less than 0
.
static method CellFrame.Network.NodeInfo.read(chainNet: CellFrame.Network.Net, nodeAddress: CellFrame.Network.NodeAddr) -> CellFrame.Network.NodeInfo
Reads a node information from a database. Returns NodeInfo
object if successful.
class CellFrame.Network.NodeClient
This class provides methods for working with a chain net client and handling connection.
static method CellFrame.Network.NodeClient.clientConnect(net: CellFrame.Network.Net, nodeInfo: CellFrame.Network.NodeInfo, activeChannels: str) -> CellFrame.Network.NodeClient
Creates connection to server by the net
, nodeInfo
and activeChannels
. Returns the NodeClient
object.
static method CellFrame.Network.NodeClient.nodeClientConnect(net: CellFrame.Network.Net, nodeInfo: CellFrame.Network.NodeInfo) -> CellFrame.Network.NodeClient
Creates a connection to the server by the net
and nodeInfo
. Returns the NodeClient
object.
object method CellFrame.Network.NodeClient.close() -> int
Closes a connection to the server. Returns 0
.
object method CellFrame.Network.NodeClient.sendChPkt(chId: int, type: int, buffer: bytes) -> int
Sends a stream request to the server. Returns 0
if successful, otherwise error code less than 0
.
object method CellFrame.Network.NodeClient.wait(waitedState: int, timeout: int) -> int
Waits for completion of a request. The waitedState
is a state which we will wait, for example, 101
GlobalDB has been updated.
Possible waitedState
values are given in the table:
Value | State |
---|---|
-1 |
NODE_CLIENT_STATE_ERROR |
0 |
NODE_CLIENT_STATE_DISCONNECTED |
1 |
NODE_CLIENT_STATE_GET_NODE_ADDR |
2 |
NODE_CLIENT_STATE_NODE_ADDR_LEASED |
3 |
NODE_CLIENT_STATE_PING |
4 |
NODE_CLIENT_STATE_PONG |
5 |
NODE_CLIENT_STATE_CONNECTING |
100 |
NODE_CLIENT_STATE_ESTABLISHED |
101 |
NODE_CLIENT_STATE_SYNC_GDB_UPDATES |
102 |
NODE_CLIENT_STATE_SYNC_GDB |
103 |
NODE_CLIENT_STATE_SYNC_GDB_RVRS |
110 |
NODE_CLIENT_STATE_SYNC_CHAINS_UPDATES |
111 |
NODE_CLIENT_STATE_SYNC_CHAINS |
112 |
NODE_CLIENT_STATE_SYNC_CHAINS_RVRS |
120 |
NODE_CLIENT_STATE_SYNCED |
130 |
NODE_CLIENT_STATE_CHECKED |
The timeout
is specified in milliseconds.
Returns | Describtion |
---|---|
0 |
if the current state has been changed to the waitState |
-1 |
if the timeout has ended |
-2 |
if waitedState can't be achieved |
-3 |
if C plain structure is NULL |
static method CellFrame.Network.NodeClient.setCallbacks(client: CellFrame.Client, chId: int, buffer: bytes) -> int
Sets callbacks functions for the client
. The chId
can take the following values: 67
- "C" and 78
- "N". Returns 0
if successful, otherwise -1
.
class CellFrame.Network.NodeAddr
This class provides methods for working with a node address.
class CellFrame.Network.Net
This class provides methods for working with a chain net.
staic method CellFrame.Network.Net.loadAll() -> int
Loads network configuration settings. Returns 0
if successful.
object method CellFrame.Network.Net.stateGoTo(netState: CellFrame.ChainNetState) -> int
Sets a current network state. The netState
should be a NetState
object. Returns 0
if successful.
object method CellFrame.Network.Net.start() -> int
Switches the current network state to the STATE_ONLINE state. Returns 0
if successful.
object method CellFrame.Network.Net.stop() -> int
Switches the current network state to the STATE_OFFLINE state. Returns 0
if successful.
object method CellFrame.Network.Net.linksEstablish() -> int
Switches the current network state to the LINKS_ESTABLISHED state. Returns 0
if successful.
object method CellFrame.Network.Net.syncChains() -> int
Switches the current network state to the SYNC_CHAINS state. Returns 0
if successful.
object method CellFrame.Network.Net.syncGdb() -> int
Switches the current network state to the SYNC_GDB state. Returns 0
if successful.
object method CellFrame.Network.Net.syncAll() -> int
Switches the current network state to the SYNC_GDB state. Returns 0
if successful.
Not implementations yet.
static method CellFrame.Network.Net.byName(netName: str) -> Optional[CellFrame.ChainNet]
Finds a chain net by the netName
. Returns the ChainNet
object if it was found, otherwise None
.
static method CellFrame.Network.Net.byId(netId: CellFrame.ChainNetID) -> CellFrame.ChainNet
Finds a chain net by the netId
. Returns the ChainNet
object if it was found.
static method CellFrame.Network.Net.idByName(netName: str) -> CellFrame.ChainNetID
Finds a chain net identificator by the netName
. Returns the CellFrame.ChainNetID
object if it was found.
static method CellFrame.Network.Net.ledgerByNetName(netName: str) -> CellFrame.ChainLedger
Finds a chain ledger by the netName
. Returns the Ledger
object if it was found.
object method CellFrame.Network.Net.getChainByName(chainName: str) -> CellFrame.Chain
Gets a chain by the chainName
. Returns the Chain
object if it was found.
object method CellFrame.Network.Net.getCurAddr() -> CellFrame.Network.NodeAddr
Gets a current address. Returns the NodeAddr
object.
object method CellFrame.Network.Net.getCurCell() -> CellFrame.Chain.CellID
Gets a current cell identificator. Returns the CellID
object.
static method CellFrame.Network.Net.getGdbGroupMempool(chain: CellFrame.Chain) -> str
Gets a mempool string.
object method CellFrame.Network.Net.getGdbGroupMempoolByChainType(chainType: CellFrame.Chain.ChainType) -> str
Gets a mempool string by the chainType
.
Not implementations yet.
object method CellFrame.Network.Net.getChainByChainType(chainType: CellFrame.ChainType) -> CellFrame.Chain
Gets a chain by the chainType
. Returns the CellFrame.Chain
object.
object method CellFrame.Network.Net.getLedger(chainType: CellFrame.Chain.ChainType) -> CellFrame.ChainLedger
Gets a ledger. Returns the Ledger
object.
object method CellFrame.Network.Net.getName() -> str
Gets a net name string.
object method CellFrame.Network.Net.getTxByHash(hash: DAP.Crypto.HashFast) -> CellFrame.Network.DatumTx
Gets a datum transaction by a hash. The hash
must be a HashFast
object. Returns an instance of the ChainDatumTx
object.
object method CellFrame.Network.Net.addNotify(callbackFunc: Callable) -> None
Adds a callback function to the notification list. The callbackFunc
must have a f(opCode: str, group: str, key: str, value: bytes) -> None
format. When calling the callbackFunc
function, the following arguments will be passed: the opCode
is a operation code, the group
is a group name, the key
is a key and the value
is byte value. Returns None
. See A Notification Example.
getter CellFrame.Network.Net.id -> CellFrame.Network.NetID
Gets a net ID. Returns an an instance of the NetID
object.
class CellFrame.Network.NetID
This class representes an net identicator.
static method CellFrame.Network.NetID.fromStr(id: str) -> CellFrame.Network.NetID
Creates a net identificator object. The id
must be a string. Returns an instance of NetID
object.
class CellFrame.Network.NetState
This class provides methods for working with a net state.
static method CellFrame.Network.NetNode.NET_STATE_OFFLINE() -> CellFrame.Network.NetState
Returns the NetState
object with the NET_STATE_OFFLINE state.
static method CellFrame.Network.NetNode.NET_STATE_LINKS_PREPARE() -> CellFrame.Network.NetState
Returns the NetState
object with the NET_STATE_LINKS_PREPARE state.
static method CellFrame.Network.NetState.NET_STATE_LINKS_CONNECTING() -> CellFrame.ChainNetState
Returns the NetState
object with the NET_STATE_LINKS_CONNECTING state.
static method CellFrame.Network.NetState.NET_STATE_LINKS_ESTABLISHED() -> CellFrame.Network.NetState
Returns the NetState
object with the NET_STATE_LINKS_ESTABLISHED state.
static method CellFrame.Network.NetState.NET_STATE_ADDR_REQUEST() -> CellFrame.Network.NetState
Returns the NetState
object with the NET_STATE_ADDR_REQUEST state.
static method CellFrame.Network.NetState.NET_STATE_SYNC_GDB() -> CellFrame.Network.NetState
Returns the NetState
object with the NET_STATE_SYNC_GDB state.
static method CellFrame.Network.NetState.NET_STATE_SYNC_CHAINS() -> CellFrame.Network.NetState
Returns the NetState
object with the NET_STATE_SYNC_CHAINS state.
class CellFrame.Network.Service
This class provides methods for working with a chain net service.
constructor CellFrame.Network.Service(uid: CellFrame.Network.ServiceUID, section: str, callbackRequested: Callable, callbackResponseSuccess: Callable, callbackResponseError: Callable, callbackReceiptNextSuccess: Callable, callbackCustomData: Callable) -> CellFrame.ChainNetSrv
Constructs an instance. The uid
is an UID of a service, it must be a ServiceUID
. The section
is a name of the configuration file section which describes a price list of the service, it must be a string.
The callback functions must have a f(service: CellFrame.Network.Service, id: int, srvClient: CellFrame.Network.ServiceClient, customData: bytes) -> int
format.
getter CellFrame.Network.Service.uid -> CellFrame.Network.ServiceUID
Gets a service UID. Returns a ServiceUID
object if successful.
getter CellFrame.Network.Service.gracePeriod -> int
Gets a grace period.
class CellFrame.Network.ServiceClient
This class provides methods for working with a chain net service client.
constructor CellFrame.Network.ServiceClient(net: CellFrame.Network.Net, addr: str, port: int, callback_connected: Callable, callback_disconnected: Callable, callback_deleted: Callable, callback_check: Callable, callback_sign: Callable, callback_success: Callable, callback_error: Callable, callback_data: Callable) -> CellFrame.Network.ServiceClient
Constructs an instance of ServiceClient
object.
method CellFrame.Network.ServiceClient.check(netID: CellFrame.Network.NetID, srvUID: CellFrame.ChainNetSrvUID, data: bytes) -> int
Cheks a data.
method CellFrame.Network.ServiceClient.request(net: CellFrame.Network.Net, srvUID: CellFrame.ChainNetSrvUID, hash: CellFrame.ChainHashFast) -> int
Sends a request.
method CellFrame.Network.ServiceClient.write(srvUID: CellFrame.Network.ServiceUID, data: bytes) -> int
Writes a data.
class CellFrame.Network.ServicePrice
This class provides methods for working with a chain net service client.
getter CellFrame.Network.ServicePrice.wallet -> None
Not implemented yet.
getter CellFrame.Network.ServicePrice.netName -> str
Gets a net name.
getter CellFrame.Network.ServicePrice.net -> CellFrame.Network.Net
Gets a net.
getter CellFrame.Network.ServicePrice.valueDatoshi -> int
Gets a value datoshi.
getter CellFrame.Network.ServicePrice.token -> str
Gets a token.
getter CellFrame.Network.ServicePrice.units -> int
Gets units.
getter CellFrame.Network.ServicePrice.unitsUid -> CellFrame.Network.ServicePriceUnitUID
Gets an unit UID.
class CellFrame.Network.ServiceOrder
This class provides methods for work with an order.
constructor CellFrame.Network.ServiceOrder(net: CellFrame.Network.Net, direction: CellFrame.Network.ServiceOrderDirection, srvUID: CellFrame.Network.ServiceUID, nodeAddr: CellFrame.Network.NodeAddr, txCondHash: DAP.Crypto.HashFast, price: int, priceUnit: CellFrame.Network.ServicePriceUnitUID, priceTicker: str, expires: float, ext: bytes, key: DAP.Crypto.CryptoKey)
Creates an instance of a ServiceOrder
object. The net
is a network in which the order is being created, it must be a Net
object. The direction
can be obtained by one of the methods of the ServiceOrderDirection
object. The srvUID
is a service UID, it must be a ServiceUID
object. The nodeAddr
is a node address. The txCondHash
is a conditioned transaction hash. The price
is a service price in datoshi. The priceUnit
is a price unit, it can be obtained by one of the methods of the ServicePriceUnitUID
object. The priceTicker
is a service price ticker. The expires
is a timestamp when an order expires. The ext
is a extension any data. The key
is a key used to sign the order.
object method CellFrame.Network.ServiceOrder.size() -> int
Gets a size of the order.
static method CellFrame.Network.ServiceOrder.find(net: CellFrame.ChainNet, orderHash: str) -> CellFrame.Network.ServiceOrder
Finds an order by a hash. The net
is a network in which the order is being searched. The orderHash
is a hash string of the order to be find out. Returns an instance of a Network.ServiceOrder
object if the order was found or None
if it wasn't.
static method CellFrame.Network.ServiceOrder.delete(net: CellFrame.ChainNet, orderHash: Union[str, HashFast) -> int
Deletes an order by a hash. The net
is a network in which the order is being deleted. The orderHash
is a hash string of the order to be find out or an instance of a HashFast
object. Returns 0
if the order was deleted or less than 0
if it wasn't.
object method CellFrame.Network.ServiceOrder.save(net: CellFrame.Network.Net) -> int
Saves an order. The net
is a network in which the order is being saved. Returns 0
if the order was saved or less than 0
if it wasn't.
static method CellFrame.Network.ServiceOrder.getGdbGroup(net: CellFrame.Network.Net) -> str
Gets a GDB group name of a network. The net
is a network whose group name you need to get. Returns a group name string of a format "<group name>.service.orders".
static method CellFrame.Network.ServiceOrder.getNodelistGroup(net: CellFrame.ChainNet) -> str
Gets a node list name of a network. The net
is a network whose node list name you need to get. Returns a group name string of a format "<group name>.service.orders.static_nodelist".
static method CellFrame.Network.ServiceOrder.addNotify(net: CellFrame.ChainNet, callbackFunc: Callable) -> None
Adds a callback function to a network notifier. The net
is a network in which is being added. The callbackFunc
is a callback function that is called when an order is added into the GDB. The callbackFunc
must have the f(opCode: str, group: str, key: str, data: bytes)
format. The opCode
is an operation code. The group
is a group name in which an order is added. The key
is a key that is added. The data
ia a data that is added.
getter CellFrame.Network.ServiceOrder.version -> int
Gets a version of an order.
getter CellFrame.Network.ServiceOrder.uid -> CellFrame.ChainNetSrvUID
Gets an UID of an order.
getter CellFrame.Network.ServiceOrder.direction -> CellFrame.ChainNetSrvOrderDirection
Gets a direction of an order.
getter CellFrame.Network.ServiceOrder.nodeAddr -> CellFrame.ChainNodeAddr
Gets a node address of an order.
getter CellFrame.Network.ServiceOrder.condHash -> CellFrame.ChainHashFast
Gets a conditioned transaction hash of an order.
getter CellFrame.Network.ServiceOrder.priceUnit -> CellFrame.ChainNetSrvPriceUnitUID
Gets a price unit of an order.
getter CellFrame.Network.ServiceOrder.tsCreated -> int
Gets a datetime when an order was created.
getter CellFrame.Network.ServiceOrder.tsExpires -> int
Gets a datetime when an order expires.
getter CellFrame.Network.ServiceOrder.srvPrice -> int
Gets a service price in datoshi of an order.
getter CellFrame.Network.ServiceOrder.srvPriceTicker -> str
Gets a service price ticker of an order.
getter CellFrame.Network.ServiceOrder.extSize -> int
Gets a extension size of an order.
getter CellFrame.Network.ServiceOrder.ext -> bytes
Gets a extension of an order. If extSize
is 0
returns None
.
getter CellFrame.Network.ServiceOrder.sign -> CellFrame.Sign
Gets a sign. Returns an instance of a Sign
object or None
.
class CellFrame.Network.ServiceClientRemote
This class provides methods for working with a chain net service client.
getter CellFrame.Network.ServiceClientRemote.ch -> None
Not implemented yet.
getter CellFrame.Network.ServiceClientRemote.tsCreated -> int
Gets a datetime of creation.
getter CellFrame.Network.ServiceClientRemote.Created -> datetime.datetime
Gets a datetime of creation.
getter CellFrame.Network.ServiceClientRemote.streamWorker -> None
Not implemented yet.
getter CellFrame.Network.ServiceClientRemote.sessionId -> int
Gets a session ID.
getter CellFrame.Network.ServiceClientRemote.bytesReceived -> int
Gets a number of bytes received.
getter CellFrame.Network.ServiceClientRemote.bytesSend -> int
Gets a number of bytes sent.
class CellFrame.Network.ServiceOrderDirection
This class provides methods for work with an order direction.
static method CellFrame.Network.ServiceOrderDirection.getDirBuy() -> CellFrame.Network.ServiceOrderDirection
Creates a new instance of ServiceOrderDirection
object corresponding to the buy direction.
static method CellFrame.Network.getDirSell() -> CellFrame.Network.ServiceOrderDirection
Creates a new instance of ServiceOrderDirection
object corresponding to the sell direction.
static method CellFrame.Network.getDirUndefined() -> CellFrame.Network.ServiceOrderDirection
Creates a new instance of ServiceOrderDirection
object corresponding to the undefined direction.
class CellFrame.Network.ServiceUID
This class provides methods for working with a service UID.
constructor CellFrame.Network.ServiceUID(uid: int)
Construct an instance. The uid
is a service UID.
class CellFrame.Network.ServicePriceUnitUID
This class representes methods for work with a price unit UID.
static method CellFrame.Network.ServicePriceUnitUID.undefined() -> CellFrame.Network.ServicePriceUnitUID
Creates a new instance of ServicePriceUnitUID
object corresponding to the undefined unit.
static method CellFrame.Network.ServicePriceUnitUID.mb() -> CellFrame.Network.ServicePriceUnitUID
Creates a new instance of ServicePriceUnitUID
object corresponding to the megabytes unit.
static method CellFrame.Network.ServicePriceUnitUID.sec() -> CellFrame.Network.ServicePriceUnitUID
Creates a new instance of ServicePriceUnitUID
object corresponding to the seconds unit.
static method CellFrame.Network.ServicePriceUnitUID.day() -> CellFrame.Network.ServicePriceUnitUID
Creates a new instance of ServicePriceUnitUID
object corresponding to the days unit.
static method CellFrame.Network.ServicePriceUnitUID.kb() -> CellFrame.Network.ServicePriceUnitUID
Creates a new instance of ServicePriceUnitUID
object corresponding to the kilobytes unit.
static method CellFrame.Network.ServicePriceUnitUID.b() -> CellFrame.Network.ServicePriceUnitUID
Creates a new instance of ServicePriceUnitUID
object corresponding to the bytes unit.