- Latest Versions
| Name | Version | Description |
|---|---|---|
| Ming Ke Ming (名可名) | Decentralized User Identity Authentication | |
| Dao Ke Dao (道可道) | Universal Message Module | |
| DIMP (去中心化通讯协议) | Decentralized Instant Messaging Protocol |
- Account
- Address
- BTC
- ETH
- Meta
- MKM (Default)
- BTC
- ETH
- Document
- Visa (User)
- Profile
- Bulletin (Group)
- Address
- Message Contents
- Text Content
- File Content
- Image Content
- Audio Content
- Video Content
- Page Content
- Name Card
- Quote Content
- Money Content
- Transfer Money
- Combine Forward
- System Commands
- Meta Command
- Document Command
- Receipt Command
- History Command
- Group Command
- Invite
- Expel
- Query
- Quit
- Join
from typing import Optional
from dimp import Address, ConstantString
from dimax import BaseAddressFactory
from dimax.mem.ext import address_cache
class CompatibleAddressFactory(BaseAddressFactory):
"""Address factory with a fallback for unsupported address types."""
# Call it when received 'UIApplicationDidReceiveMemoryWarningNotification',
# this will remove 50% of cached objects
#
# :return number of survivors
def reduce_memory(self) -> int:
cache = address_cache()
return cache.reduce_memory()
# Override
def _parse(self, address: str) -> Optional[Address]:
try:
res = super()._parse(address=address)
if res is not None:
return res
except AssertionError as error:
# FIXME:
raise AssertionError('invalid address: %s, error: %s' % (address, error))
#
# TODO: parse for other types of address
#
length = len(address)
if 4 <= length <= 64:
return UnknownAddress(string=address)
raise ValueError('invalid address: %s' % address)
# Unsupported Address
# ~~~~~~~~~~~~~~~~~~~
class UnknownAddress(ConstantString, Address):
"""A fallback Address for strings not recognised by any factory."""
def __init__(self, string: str):
super().__init__(string=string)
@property # Override
def network(self) -> int:
return 0 # EntityType.USERfrom typing import Optional
from dimp import StrMap, Meta
from dimax import BaseMetaFactory, DefaultMeta, BTCMeta, ETHMeta
from dimax.mkm.meta_factory import doc_helper
from dimax.protocol import MetaType
class CompatibleMetaFactory(BaseMetaFactory):
"""Meta factory that dispatches by version string (mkm/btc/eth)."""
# Override
def parse_meta(self, meta: StrMap) -> Optional[Meta]:
helper = doc_helper()
version = helper.get_meta_type(meta=meta)
if version in (MetaType.MKM, 'mkm', 'MKM'):
out = DefaultMeta(meta=meta)
elif version in (MetaType.BTC, 'btc', 'BTC'):
out = BTCMeta(meta=meta)
elif version in (MetaType.ETH, 'eth', 'ETH'):
out = ETHMeta(meta=meta)
else:
# TODO: other types of meta
raise TypeError('unknown meta type: %s' % version)
return out if out.is_valid else Nonefrom dimp import Address, Meta, Content, Command
from dimp import ContentType
from dimax import ExtensionLoader, ContentParser, CommandParser
from dimax.protocol import MetaType
from .compat.address import CompatibleAddressFactory
from .compat.meta import CompatibleMetaFactory
# Extensions Loader
# ~~~~~~~~~~~~~~~~~
class CommonExtensionLoader(ExtensionLoader):
# Override
def register_address_factory(self):
Address.set_factory(factory=CompatibleAddressFactory())
# Override
def register_meta_factories(self):
mkm = CompatibleMetaFactory(version=MetaType.MKM)
btc = CompatibleMetaFactory(version=MetaType.BTC)
eth = CompatibleMetaFactory(version=MetaType.ETH)
Meta.set_factory(version=MetaType.MKM, factory=mkm)
Meta.set_factory(version=MetaType.BTC, factory=btc)
Meta.set_factory(version=MetaType.ETH, factory=eth)
# Override
def register_content_factories(self):
super().register_content_factories()
# Application Customized
factory = ContentParser(content_class=AppCustomizedContent)
Content.set_factory(msg_type=ContentType.APPLICATION, factory=factory)
Content.set_factory(msg_type=ContentType.CUSTOMIZED, factory=factory)
# Override
def register_command_factories(self):
super().register_command_factories()
# Handshake
Command.set_factory(cmd=HandshakeCommand.HANDSHAKE,
factory=CommandParser(command_class=BaseHandshakeCommand))NOTE:
AppCustomizedContent,HandshakeCommandandBaseHandshakeCommandare application-level classes (like the dartprotocol/customized.dartandprotocol/handshake.dart); they are not shipped indimax. The registration primitives shown here —ContentParser,CommandParser,Content.set_factory,Command.set_factoryandContentType.APPLICATION/ContentType.CUSTOMIZED— are all real.
You must ensure that every Address you extend has a Meta type that can correspond to it one by one.