]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/yggdrasil/yggdrasil.go
Merge branch 'develop'
[nncp.git] / src / yggdrasil / yggdrasil.go
index ad52744b2ec52140524d1f48223bcf8c64eb82fd..010e4159ba2f2609540e0cc7c2c31fcd5fa0d088 100644 (file)
@@ -42,14 +42,6 @@ import (
 
 const DefaultPort = 5400
 
-// Copy-pasted from yggdrasil-go/src/ipv6rwc/ipv6rwc.go,
-// because they are non-exportable.
-const (
-       typeKeyDummy = iota
-       typeKeyLookup
-       typeKeyResponse
-)
-
 var (
        glog *gologme.Logger
 
@@ -87,10 +79,6 @@ func ycoreStart(cfg *ycfg.NodeConfig, port int, mcasts []string) (*ycore.Core, e
                )
        }
 
-       sk, err := hex.DecodeString(cfg.PrivateKey)
-       if err != nil {
-               panic(err)
-       }
        options := []ycore.SetupOption{
                ycore.NodeInfo(cfg.NodeInfo),
                ycore.NodeInfoPrivacy(cfg.NodeInfoPrivacy),
@@ -114,7 +102,11 @@ func ycoreStart(cfg *ycfg.NodeConfig, port int, mcasts []string) (*ycore.Core, e
                options = append(options, ycore.AllowedPublicKey(k[:]))
        }
 
-       core, err := ycore.New(sk[:], glog, options...)
+       err = cfg.GenerateSelfSignedCertificate()
+       if err != nil {
+               return nil, err
+       }
+       core, err := ycore.New(cfg.Certificate, glog, options...)
        if err != nil {
                return nil, err
        }
@@ -215,7 +207,7 @@ func NewConn(aliases map[string]string, in string) (net.Conn, error) {
                return e.DialTCP(&net.TCPAddr{IP: ipTheir, Port: port})
        }
        cfg := ycfg.NodeConfig{
-               PrivateKey:      prvHex,
+               PrivateKey:      prvRaw,
                Peers:           peers,
                NodeInfo:        map[string]interface{}{"name": "NNCP"},
                NodeInfoPrivacy: true,
@@ -233,27 +225,6 @@ func NewConn(aliases map[string]string, in string) (net.Conn, error) {
        return e.DialTCP(&net.TCPAddr{IP: ipTheir, Port: port})
 }
 
-type OOBState struct {
-       c      *ycore.Core
-       subnet yaddr.Subnet
-}
-
-func (state *OOBState) Handler(fromKey, toKey ed25519.PublicKey, data []byte) {
-       if len(data) != 1+ed25519.SignatureSize {
-               return
-       }
-       if data[0] == typeKeyLookup {
-               snet := *yaddr.SubnetForKey(toKey)
-               sig := data[1:]
-               if snet == state.subnet && ed25519.Verify(fromKey, toKey[:], sig) {
-                       state.c.SendOutOfBand(fromKey, append(
-                               []byte{typeKeyResponse},
-                               ed25519.Sign(state.c.PrivateKey(), fromKey[:])...,
-                       ))
-               }
-       }
-}
-
 func NewListener(aliases map[string]string, in string) (net.Listener, error) {
        // yggdrasils://PRV[:PORT]?[bind=BIND][&pub=PUB][&peer=PEER][&mcast=REGEX[:PORT]]
        u, err := url.Parse(in)
@@ -326,7 +297,7 @@ func NewListener(aliases map[string]string, in string) (net.Listener, error) {
                return e.ListenTCP(&net.TCPAddr{IP: ipOur, Port: port})
        }
        cfg := ycfg.NodeConfig{
-               PrivateKey:        prvHex,
+               PrivateKey:        ycfg.KeyBytes(prvRaw),
                Listen:            binds,
                AllowedPublicKeys: pubs,
                Peers:             peers,
@@ -337,11 +308,6 @@ func NewListener(aliases map[string]string, in string) (net.Listener, error) {
        if err != nil {
                return nil, err
        }
-       oobState := OOBState{core, *yaddr.SubnetForKey(core.PublicKey())}
-       if err := core.SetOutOfBandHandler(oobState.Handler); err != nil {
-               core.Stop()
-               return nil, err
-       }
        e, err = NewTCPIPEndpoint(core, ipOur, uint32(core.MTU()))
        if err != nil {
                core.Stop()