diff --git a/database/db.go b/database/db.go index 8d20e64..fdba042 100644 --- a/database/db.go +++ b/database/db.go @@ -66,6 +66,22 @@ func (db *DB) SaveRoute(resp *routerpc.AddHostResponse) error { return nil } +func (db *DB) GetRouteForHost(name string) (*Route, error) { + rows, err := r.Table("routes").Filter(r.Row.Field("hostname", name).Or(r.Row.Field("onionhostname", name))).Run(db.s) + if err != nil { + return nil, err + } + + result := &Route{} + + err = rows.One(result) + if err != nil { + return nil, err + } + + return result, nil +} + // GetAllRoutes fetches all of the route entries from the database // and returns them. This is intended for the startup process or // admin tooling.