Differences From
Artifact [8808dbd7a5]:
11 11 pol_reg: bool
12 12 }
13 13 local struct srv {
14 14 sources: lib.mem.ptr(lib.store.source)
15 15 webmgr: lib.net.mg_mgr
16 16 webcon: &lib.net.mg_connection
17 17 cfg: cfgcache
18 + id: rawstring
18 19 }
19 20
20 21 terra cfgcache:free() -- :/
21 22 self.secret:free()
22 23 self.instance:free()
23 24 end
24 25
................................................................................
539 540 if self.sources(i).backend ~= nil and
540 541 self.sources(i).backend.actor_auth_pw ~= nil then
541 542 var aid,uid,newhnd = self.sources(i):actor_auth_pw(ip,user,pw)
542 543 if aid ~= 0 then
543 544 if uid == 0 then
544 545 lib.dbg('new user just logged in, creating account entry')
545 546 var kbuf: uint8[lib.crypt.const.maxdersz]
546 - var newkp = lib.crypt.genkp()
547 - var privsz = lib.crypt.der(false,&newkp,&kbuf[0])
548 - var na = lib.store.actor {
549 - id = 0; nym = nil; handle = newhnd.ptr;
550 - origin = 0; bio = nil; avatar = nil;
551 - knownsince = lib.osclock.time(nil);
552 - rights = lib.store.rights_default();
553 - title = nil, key = [lib.mem.ptr(uint8)] {
554 - ptr = &kbuf[0], ct = privsz
555 - };
556 - }
547 + var na = lib.store.actor.mk(&kbuf[0])
557 548 var newuid: uint64
558 549 if self.sources(i).backend.actor_create ~= nil then
559 550 newuid = self.sources(i):actor_create(&na)
560 551 else newuid = self:actor_create(&na) end
561 552
562 553 if self.sources(i).backend.actor_auth_register_uid ~= nil then
563 554 self.sources(i):actor_auth_register_uid(aid,newuid)
................................................................................
574 565 --9twh8y94i5c1qqr7hxu20fyd
575 566 terra cfgcache.methods.load :: {&cfgcache} -> {}
576 567 terra cfgcache:init(o: &srv)
577 568 self.overlord = o
578 569 self:load()
579 570 end
580 571
581 -srv.methods.start = terra(self: &srv, befile: rawstring)
572 +terra srv:setup(befile: rawstring)
582 573 cfg(self, befile)
583 574 var success = false
584 575 if self.sources.ct == 0 then lib.bail('no data sources specified') end
585 576 for i=0,self.sources.ct do var src = self.sources.ptr + i
586 577 lib.report('opening data source ', src.id.ptr, '(', src.backend.id, ')')
587 578 src.handle = src.backend.open(src)
588 579 if src.handle ~= nil then success = true end
589 580 end
590 581 if not success then
591 582 lib.bail('could not connect to any data sources!')
592 583 end
584 +end
593 585
586 +terra srv:start(iname: rawstring)
587 + self:conprep(lib.store.prepmode.full)
594 588 self.cfg:init(self)
595 -
596 589 var dbbind = self:conf_get('bind')
590 + if iname == nil then iname = lib.proc.getenv('parsav_instance') end
591 + if iname == nil then
592 + self.id = self.cfg.instance.ptr;
593 + -- let this leak -- it'll be needed for the lifetime of the process anyway
594 + else self.id = iname end
595 +
596 + if iname ~= nil then
597 + lib.report('parsav instance "',iname,'" starting')
598 + end
599 +
597 600 var envbind = lib.proc.getenv('parsav_bind')
598 601 var bind: rawstring
599 602 if envbind ~= nil then
600 603 bind = envbind
601 604 elseif dbbind.ptr ~= nil then
602 605 bind = dbbind.ptr
603 - else bind = '[::]:10917' end
606 + else bind = '[::1]:10917' end
604 607
605 608 lib.report('binding to ', bind)
606 609 lib.net.mg_mgr_init(&self.webmgr)
607 610 self.webcon = lib.net.mg_http_listen(&self.webmgr, bind, handle.http, self)
608 611
609 612 if dbbind.ptr ~= nil then dbbind:free() end
610 613 end
611 614
612 -srv.methods.poll = terra(self: &srv)
615 +terra srv:poll()
613 616 lib.net.mg_mgr_poll(&self.webmgr,1000)
614 617 end
615 618
616 -srv.methods.shutdown = terra(self: &srv)
619 +terra srv:shutdown()
617 620 lib.net.mg_mgr_free(&self.webmgr)
618 621 for i=0,self.sources.ct do var src = self.sources.ptr + i
619 622 lib.report('closing data source ', src.id.ptr, '(', src.backend.id, ')')
620 623 src:close()
621 624 end
622 625 self.sources:free()
623 626 end