func (this *Tunneld) onToxnetFriendRequest(t *tox.Tox, friendId string, message string, userData interface{}) { debug.Println(friendId, message) t.FriendAddNorequest(friendId) t.WriteSavedata(fname) }
func makeTox(name string) *tox.Tox { fname = fmt.Sprintf("./%s.data", name) var nickPrefix = fmt.Sprintf("%s.", name) var statusText = fmt.Sprintf("%s of toxtun", name) opt := tox.NewToxOptions() if tox.FileExist(fname) { data, err := ioutil.ReadFile(fname) if err != nil { errl.Println(err) } else { opt.Savedata_data = data opt.Savedata_type = tox.SAVEDATA_TYPE_TOX_SAVE } } port := 33445 var t *tox.Tox for i := 0; i < 7; i++ { opt.Tcp_port = uint16(port + i) opt.Tcp_port = 0 t = tox.NewTox(opt) if t != nil { break } } if t == nil { panic(nil) } info.Println("TCP port:", opt.Tcp_port) for i := 0; i < len(server)/3; i++ { r := i * 3 r1, err := t.Bootstrap(server[r+0].(string), server[r+1].(uint16), server[r+2].(string)) r2, err := t.AddTcpRelay(server[r+0].(string), server[r+1].(uint16), server[r+2].(string)) info.Println("bootstrap:", r1, err, r2, i, r) } pubkey := t.SelfGetPublicKey() seckey := t.SelfGetSecretKey() toxid := t.SelfGetAddress() debug.Println("keys:", pubkey, seckey, len(pubkey), len(seckey)) info.Println("toxid:", toxid) defaultName, err := t.SelfGetName() humanName := nickPrefix + toxid[0:5] if humanName != defaultName { t.SelfSetName(humanName) } humanName, err = t.SelfGetName() debug.Println(humanName, defaultName, err) defaultStatusText, err := t.SelfGetStatusMessage() if defaultStatusText != statusText { t.SelfSetStatusMessage(statusText) } debug.Println(statusText, defaultStatusText, err) sz := t.GetSavedataSize() sd := t.GetSavedata() debug.Println("savedata:", sz, t) debug.Println("savedata", len(sd), t) err = t.WriteSavedata(fname) debug.Println("savedata write:", err) // add friend norequest fv := t.SelfGetFriendList() for _, fno := range fv { fid, err := t.FriendGetPublicKey(fno) if err != nil { debug.Println(err) } else { t.FriendAddNorequest(fid) } } debug.Println("add friends:", len(fv)) return t }