net2o-msg.fs 2.5 KB
Newer Older
bernd's avatar
bernd committed
1 2
\ messages                                           06aug2014py

bernd's avatar
bernd committed
3
\ Copyright (C) 2014   Bernd Paysan
bernd's avatar
bernd committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17

\ This program is free software: you can redistribute it and/or modify
\ it under the terms of the GNU Affero General Public License as published by
\ the Free Software Foundation, either version 3 of the License, or
\ (at your option) any later version.

\ This program is distributed in the hope that it will be useful,
\ but WITHOUT ANY WARRANTY; without even the implied warranty of
\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
\ GNU Affero General Public License for more details.

\ You should have received a copy of the GNU Affero General Public License
\ along with this program.  If not, see <http://www.gnu.org/licenses/>.

bernd's avatar
bernd committed
18 19
get-current also net2o-base definitions

20
$34 net2o: msg ( -- o:msg ) \ push a message object
bernd's avatar
bernd committed
21 22 23 24
    msg-context @ dup 0= IF
	drop  n2o:new-msg dup msg-context !
    THEN
    n:>o buf-state 2@ msg-buf 2! ;
bernd's avatar
bernd committed
25 26 27 28 29

msg-table >table

reply-table $@ inherit-table msg-table

bernd's avatar
bernd committed
30 31 32 33
net2o' emit net2o: msg-at ( timestamp -- ) \ specify sender time
    parent @ .pubkey $@ key-table #@
    IF cell+ .ke-nick $@ F type ELSE drop parent @ .pubkey $@ 85type THEN
    ." [" .ticks ." ]: " ;
bernd's avatar
bernd committed
34
+net2o: msg-text ( $:msg -- ) \ specify message string
bernd's avatar
bernd committed
35
    $> F type ;
bernd's avatar
bernd committed
36
+net2o: msg-object ( $:hash -- ) \ specify an object, e.g. an image
bernd's avatar
bernd committed
37 38 39 40 41 42
    $> ." wrapped object: " 85type F cr ;
+net2o: msg-sig ( $:signature -- ) \ detached signature
    $>
    msg-buf 2@ drop buf-state 2@ drop over - 3 - 2 pick - c:0key c:hash
    keysize 2* <> !!keysize!!
    parent @ .pubkey $@ keysize <> !!keysize!! ed-verify .check F cr ;
bernd's avatar
bernd committed
43 44 45 46

gen-table $freeze
' context-table is gen-table

bernd's avatar
bernd committed
47 48 49 50
set-current

User <msg-buf

bernd's avatar
bernd committed
51 52 53 54 55 56
: <msg ( -- )
    \G start a msg block
    msg cmdbuf$ + <msg-buf ! ;
: msg> ( -- )
    \G end a msg block by adding a signature
    <msg-buf @ cmdbuf$ + over -
bernd's avatar
bernd committed
57 58 59 60
    c:0key c:hash skc pkc ed-sign $, msg-sig endwith ;

previous

61 62 63 64 65
: send-text ( addr u -- )
    net2o-code  expect-reply
    <msg ticks lit, msg-at $, msg-text msg>
    cookie+request end-code| ;

bernd's avatar
bernd committed
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
0 [IF]
Local Variables:
forth-local-words:
    (
     (("net2o:" "+net2o:") definition-starter (font-lock-keyword-face . 1)
      "[ \t\n]" t name (font-lock-function-name-face . 3))
     ("[a-z\-0-9]+(" immediate (font-lock-comment-face . 1)
      ")" nil comment (font-lock-comment-face . 1))
    )
forth-local-indent-words:
    (
     (("net2o:" "+net2o:") (0 . 2) (0 . 2) non-immediate)
     (("[:") (0 . 1) (0 . 1) immediate)
     ((";]") (-1 . 0) (0 . -1) immediate)
    )
End:
[THEN]