[{"data":1,"prerenderedAt":413},["ShallowReactive",2],{"docs-\u002Fdocs\u002Fcore-tech\u002Fsecure-bulletin-board-system-(sbbs)":3,"docs-surround-\u002Fdocs\u002Fcore-tech\u002Fsecure-bulletin-board-system-(sbbs)":403},{"id":4,"title":5,"body":6,"description":389,"extension":395,"image":396,"meta":397,"navTitle":396,"navigation":398,"path":399,"seo":400,"stem":401,"__hash__":402},"docs\u002Fdocs\u002Fcore-tech\u002FSecure-bulletin-board-system-(SBBS).md","Secure bulletin board system (SBBS)",{"type":7,"value":8,"toc":388},"minimark",[9,13,18,22,26,29,34,42,64,95,98,101,120,142,161,164,167,192,195,200,209,213,216,220,223,244,248,251,265,306,310,321,330,344,350,367,372],[10,11,5],"h1",{"id":12},"secure-bulletin-board-system-sbbs",[14,15,17],"h2",{"id":16},"overview","Overview",[19,20,21],"p",{},"The main goal of BBS is to allow wallets to communicate with each other in a secure and asynchronous manner. Using BBS wallets allows individuals to exchange messages, even if one of the individuals is offline. In general, BBS is a virtual board, where users can place messages, and each message is encrypted. For encryption, the public key of the recipient is used. This implies that the recipient’s public key is his address in terms of this system. Every participant who is interested in messages from this board, observes and tries to decrypt new messages with his private key, and he manages to do so only if the message has been addressed to him. It consists of server and client sides. The server is implemented as a part of the node. The client is a wallet.",[14,23,25],{"id":24},"server-side","Server side",[19,27,28],{},"BBS is a part of our node, This implementation implies that messages are sent to n=32 channels, which can ultimately change. The channel is calculated from the public key (first 5 bits). A client has to subscribe to a specific channel, and the server will retranslate all of the new messages to subscribers. Also, the server receives and stores within the database all new messages and exchanges these messages with other servers using a P2P protocol. This logic is implemented in class Node::Peer. It represents the node’s peer and handles the node’s P2P message. BBS messages are a part of node P2P protocol.",[30,31,33],"h4",{"id":32},"bbssubscribe","BbsSubscribe",[19,35,36,37,41],{},"Message ",[38,39,40],"code",{},"tp"," allows clients to subscribe\u002Funsubscribe to notifications from the node about new messages.",[43,44,45,52,58],"ul",{},[46,47,48,51],"li",{},[38,49,50],{},"BbsChannel m_Channel"," – channel to listen.",[46,53,54,57],{},[38,55,56],{},"Timestamp m_TimeFrom"," – timestamp used to avoid sending of out-of-date messages.",[46,59,60,63],{},[38,61,62],{},"bool m_On"," – subscribe\u002Funsubscribe flag.",[19,65,66,67,70,71,74,75,78,79,82,83,86,87,90,91,94],{},"When the server receives this message from the peer with ",[38,68,69],{},"m_On == true"," and ",[38,72,73],{},"Node::Peer::m_Subscriptions"," list doesn’t have it (the look up is made by channel), then the node adds a new instance of ",[38,76,77],{},"Node::Bbs::Subscription"," to this list and to ",[38,80,81],{},"Node::m_Bbs::m_Subscribed",". If the node has messages for this channel that are sent after given timestamp, then it sends them as a new ",[38,84,85],{},"BbsMsg"," to this subscriber. If ",[38,88,89],{},"m_On == false"," and a given subscriber exists in ",[38,92,93],{},"m_Subscriptions"," list, the node simply removes it.",[30,96,85],{"id":97},"bbsmsg",[19,99,100],{},"A message which is used to put an encrypted message onto the board or to exchange between nodes:",[43,102,103,108,114],{},[46,104,105,107],{},[38,106,50],{}," – target channel.",[46,109,110,113],{},[38,111,112],{},"Timestamp m_TimePosted"," – timestamp, when wallet has posted message to bbs.",[46,115,116,119],{},[38,117,118],{},"ByteBuffer m_Message"," – the encrypted content.",[19,121,122,123,126,127,129,130,133,134,137,138,141],{},"When this message is received, server gets current timestamp. If ",[38,124,125],{},"m_TimePosted"," \u003C= currentTime-24 hours, i.e. to old, or ",[38,128,125],{}," > currentTime + 2 hour (someone generates messages from future), then node rejects this message. If it doesn’t have this message it stores it in database, sends ",[38,131,132],{},"BbsHaveMsg",", to inform other peers about new bbs message, and sends ",[38,135,136],{},"BbsMsg ","to subscriberd interested in messages from ",[38,139,140],{},"m_Channel",".",[19,143,144,145,148,149,152,153,155,156,158,159,141],{},"When this message is received, the server gets a current timestamp. If ",[38,146,147],{},"m_TimePosted \u003C= currentTime-24"," hours, i.e. too old, or ",[38,150,151],{},"m_TimePosted > currentTime + 2"," hours (someone generates messages from the future), then the node rejects this message. If it doesn’t have this message, it is stored in the database, and sent ",[38,154,132],{},", in order to inform other peers about new bbs message. It sends ",[38,157,85],{}," to subscribed interested in messages from ",[38,160,140],{},[30,162,132],{"id":163},"bbshavemsg",[19,165,166],{},"A Message which is used by BBS server (node) to exchange information about message that it has.",[43,168,169],{},[46,170,171,174,175,178,179,181,182,184,185,188,189,141],{},[38,172,173],{},"BbsMsgID m_Key"," – the message’s key. It is defined as a hash of the ",[38,176,177],{},"m_Message"," and the ",[38,180,140],{}," in ",[38,183,85],{},". In order to handle this message, the node checks if it already has this message. If it doesn’t, it stores it into waitlist ",[38,186,187],{},"Node::m_Bbs::m_W"," and sends ",[38,190,191],{},"BbsGetMsg",[30,193,191],{"id":194},"bbsgetmsg",[19,196,197,198,141],{},"A peer server request for bbs message, which occurs as a response to ",[38,199,132],{},[43,201,202],{},[46,203,204,206,207,141],{},[38,205,173],{}," If the node has a bbs message with a given key, it sends it back as ",[38,208,85],{},[30,210,212],{"id":211},"bbspickchannel","BbsPickChannel",[19,214,215],{},"The Client asks the server for recommended channels.",[30,217,219],{"id":218},"bbspickchannelres","BbsPickChannelRes",[19,221,222],{},"Server channel recommendation",[43,224,225],{},[46,226,227,229,230,233,234,237,238,241,242,141],{},[38,228,50],{}," - recommended channel. Once in an hour ",[38,231,232],{},"(Node::m_Cfg::m_Timeout::m_BbsCleanupPeriod_ms)"," the node tries to find a channel which is populated with less than 100 listeners ",[38,235,236],{},"(Node::m_Cfg::m_BbsIdealChannelPopulation)",". Found value is stored into ",[38,239,240],{},"m_RecommendedChannel"," and it is used as a response to ",[38,243,212],{},[14,245,247],{"id":246},"client-side","Client side",[19,249,250],{},"In the wallet, the BBS communication is placed in WalletNetworkViaBbs class. It allows to send a message to BBS and it manages BBS keys and timestamps. This class contains references to:",[43,252,253,259],{},[46,254,255,258],{},[38,256,257],{},"IWallet& m_Wallet"," - which is used for callbacks to wallet object.",[46,260,261,264],{},[38,262,263],{},"proto::FlyClient::INetwork& m_NodeNetwork"," - which is used to communicate with the node.",[19,266,267,268,271,272,275,276,279,280,283,284,287,288,290,291,294,295,298,299,302,303,305],{},"When the wallet wants to create a new address (from cli, ui) or load already-created addresses from the database, ",[38,269,270],{},"AddOwnAddress()"," is called. This method calls ",[38,273,274],{},"IWalletDB::calcKey()"," with the key type ",[38,277,278],{},"Bbs"," to generate a private key for BBS. The public key is created using ",[38,281,282],{},"proto::Sk2Pk()",". Index, which is used for generating a private key that is stored in ",[38,285,286],{},"wallet.db",". The wallet will then choose a channel. If the client has not subscribed to the chosen channel, the ",[38,289,33],{}," message is posted to the node via ",[38,292,293],{},"m_NodeNetwork",". If the wallet wants to send a message via Bbs it calls the overridden method ",[38,296,297],{},"Send()",". In this method, the given message is encrypted using ",[38,300,301],{},"proto::BbsEncrypt()"," and sent to ",[38,304,293],{},". If the wallet received the bbs message it updates the timestamp for the channel and stores them to the database.",[30,307,309],{"id":308},"usage-of-bbs-to-exchange-message","Usage of BBS to exchange message",[19,311,312,313,317,318,141],{},"There are two sides wallet ",[314,315,316],"strong",{},"A"," and wallet ",[314,319,320],{},"B",[322,323,325,70,327,329],"h5",{"id":324},"a-and-b",[314,326,316],{},[314,328,320],{},":",[43,331,332,335,338],{},[46,333,334],{},"picks or generates a pair of keys public and private",[46,336,337],{},"choose channel\u002F\u002Fasks BBS server (node) for suitable",[46,339,340,341,343],{},"sends ",[38,342,33],{}," to chosen channel, if needed",[322,345,347,348,329],{"id":346},"wallet-a","Wallet ",[314,349,316],{},[43,351,352,355,358,361],{},[46,353,354],{},"chooses the address of target recipient (his public key)",[46,356,357],{},"creates a message, it has to contain its public key as an address for answer",[46,359,360],{},"encrypts this message using pub",[46,362,363,364,366],{},"creates ",[38,365,85],{},", fills it and sends to BBS server",[322,368,347,370,329],{"id":369},"wallet-b",[314,371,320],{},[43,373,374,379,382,385],{},[46,375,376,377],{},"receives ",[38,378,85],{},[46,380,381],{},"updates timestamps for the message channel",[46,383,384],{},"tries to decrypt bbs message using the known key for message channel",[46,386,387],{},"if succeeded, it notifies wallet",{"title":389,"searchDepth":390,"depth":390,"links":391},"",2,[392,393,394],{"id":16,"depth":390,"text":17},{"id":24,"depth":390,"text":25},{"id":246,"depth":390,"text":247},"md",null,{},true,"\u002Fdocs\u002Fcore-tech\u002Fsecure-bulletin-board-system-(sbbs)",{"title":5,"description":389},"docs\u002Fcore-tech\u002FSecure-bulletin-board-system-(SBBS)","smC1mzvHMFGFiEF-uOHbDKKp7G71eV7jA-RtYIAlfh8",[404,409],{"title":405,"path":406,"stem":407,"description":408,"children":-1},"Rescan offline","\u002Fdocs\u002Fcore-tech\u002Frescan-offline","docs\u002Fcore-tech\u002FRescan-offline","This scenario is for cases when you don't want to stop running node and wallet and you wish to ensure if the balance is correct.",{"title":410,"path":411,"stem":412,"description":389,"children":-1},"Setting Up Read Only Wallet For Monitoring","\u002Fdocs\u002Fcore-tech\u002Fsetting-up-read-only-wallet-for-monitoring","docs\u002Fcore-tech\u002FSetting-up-read-only-wallet-for-monitoring",1783006082276]